Hi Developers I hope All are You fine. I need help. I make a AppLocker app and I use service to check which app i currently running. i locked app in my database with package name. When I show my lock screen From Service my Intent hit but lockScreen not Showing.How i call Activity From Service below is my Codeto start Activty from Service
if (locker_list!=null) {
if (launchapp) {
Log.d("TAG", "run: lock Screen Show");
Intent intent = new Intent(mContext, Lock_app_screen.class);
intent.putExtra("package_name", current_app);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. These restrictions help minimize interruptions for the user and keep the user more in control of what's shown on their screen.
for more...
see this
Related
I was starting activity from services till android P, but from android10 google has kept one restriction that activity cannot be started from background.
https://developer.android.com/guide/components/activities/background-starts
// below code stopped working
Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
what should i do for android10 ?
You can use a notification using setFullScreenIntent, it's the best you can do or you can ask for SYSTEM_ALERT_WINDOW permission but it doesn't work with android go devices.
It was working fine up to Oreo but after the API 28 PIE VERSION released the background service is not working properly, the exact flow is after starting the service without stopping it manually, the service automatically is being stopped when the app is killed. Can anyone tell me how to do it.
public void stopLocationService() {
Log.d(TAG, "stopLocationService: ");
Intent i = new Intent(getApplicationContext(), LocationService.class);
stopService(i);
}
public void startLocationService() {
Log.d(TAG, "startLocationService: ");
Intent intent = new Intent(getApplicationContext(), LocationService.class);
startService(intent);
}
Many android device manufacturers are using aggressive policies to save battery. When a user clears his/her app from recent tabs, the app is force closed, thus cancelling all alarms,broadcastReceivers,services etc. This happens in most of the device manufacturers like OnePlus,Huwaei, Xiaomi, Vivo, Oppo etc.
They have AutoStartManagers/AutoLaunchManagers that prevent the background running of the apps. You will have to white list your app using steps mentioned in THIS SO ANSWER.
Also visit https://dontkillmyapp.com/ to know about task killers in different device manufacturers.
I use following code to stop my app:
this.finishAffinity();
However after I finish my app I can see in the application manager my app still has stop button enabled.Does this mean the app is still running?Moreover the android studio thinks app is running too.
If I finish the app with this code:
this.finish();
System.exit(0);
Android studio treats app as finished, but app manager still shows stop button enabled.
I read calling System.exit is unpreferable way of finishing the app.
What is the correct one?
In short, don't worry about it.
You should run checks to ensure you aren't leaking a Context, but in general you don't need to worry about your App staying "active".
This simply means that it hasn't been fully terminated yet, because Android hasn't needed to do so. Until then, it keeps it partially alive to be able to bring it back quickly if the user wants it again.
This doesn't take any additional processing resources to keep it alive. Only some memory. When Android deems it necessary to claim resources, it will kill your App fully.
Just keep using finish();.
The Android Lifecycle:
If you don't want your app to be shown in the overview screen when it finishes, simply add the android:autoRemoveFromRecents="true" to your activity tag in the manifest. No need to use System.exit(0).
To Quit Application on Button click use this code :
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
Try it..
To kill the complete app and remove it from Runningapp list kill the app through its pid(its nasty)... use this lines before above code.
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
no need to use this.finish();
just finish(); is ok
app manager always show the app is running because killing a app may occur misbehavior to its activitys.
public void EXIT(View view)
{
finish();
}
android.os.Process.killProcess(android.os.Process.myPid());
I hope this is just a temporary problem and Skype allows an autostart feature.
I need to launch Skype so that it can receive Skype calls and video calls, and then launch my app. I work with the elderly s simplicity is at a premium. My app runs continuously.
The following code seems to achieve this goal in a BOOT BroadcastReceiver.
PackageManager pmi = context.getPackageManager();
String packageName ="com.skype.raider";
context.startActivity(pmi.getLaunchIntentForPackage(packageName));
Log.d("ANDRO_ASYNC",String.format("should launch Skype"));
Intent intent1 = new Intent(context,MyApp.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle bundle = new Bundle();
bundle.putInt("FromBoot",1);
intent1.putExtras(bundle);
try{ // hoping to schedule the start to after Skype has finished
Thread.sleep(20000);
}catch(InterruptedException ex){
Log.d("ANDRO_ASYNC",String.format("error in delay loop"));
}
context.startActivity(intent1);
This launches Skype and waits 20s to get sorted out before launching my app. My app ends up on the screen (desired effect).
However, it has a tiny problem for most people, but a big one for me. After the first Skype call the Blue welcome screen of Skype stays up, and the user has to press back button. Effectively this makes ending a Skype call different depending on whether it is the first or subsequent calls.
Questions.
Can I close Skype from my app?
Can I detect that Skype is finished teh call from my app?
I am quite new in android environment.
This problem occur on android 4.0.3 but it is working on android 2.2. I just could start activity after outgoing call. I just want to call back my activity to foreground while making phone call. but it is working on android 2.2 but it is not working on 4.0.3.
Here is my code. This code working on both version on incoming state.
But it is not working on 4.0.3 on outgoing intent. I call this intent from BroadcastReceiver. Please note that i do not want to end phone calling activity while my activity in foreground state. I set launch mode to "singleInstance" on Mainfest.xml.
Toast.makeText(context, "Should Start Activity", Toast.LENGTH_LONG).show();
Intent callsensorintent = new Intent();
callsensorintent.setFlags(
Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|Intent.FLAG_ACTIVITY_NEW_TASK
);
callsensorintent.setClassName(context,"com.example.test.sg.SensorUdp");
context.startActivity(callsensorintent);
Thanks
The call screen on ICS has a higher priority than before, so it will show on top over everything else when it's in the foreground. Now it even has a higher priority than the notification menu/curtain.
You can use a higher window priority for your application, e.g. WindowManager.LayoutParams.TYPE_SYSTEM_ALERT.