When using flag FLAG_ACTIVITY_NEW_TASK, if a task is already running for the activity you are now starting, I want a new activity to not be started – instead, I want the current task to simply be brought to the front of the screen it was last in.
-
How can I do it from service of other app? I would like to launch app which is in
actvityManager.getRunningAppProcesses()by service. I know how to start this app only as a new one:Context context = this.getBaseContext();PackageManager pm = context.getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(LevelappPackageName);
context.startActivity(intent);
But I would like to perfom it this way:
context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
-
I know how to find out if my app is running:
ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE ); List<RunningAppProcessInfo> App = actvityManager.getRunningAppProcesses(); for(int i = 0; i < App.size(); i++) { if(App.get(i).processName.equals("myapp"))But how can I know if some app is currently running – it is on screen at this moment?!
You will need to add an
intent-filteractionto the manifest of theActivityyou wish to start. You will also need aPendingIntentwith the correctactionthat you can send from theService. You may also need to look the manifestlaunchMode=singleTopand/orContext.startActivityIfNeeded.If an
Activityhas focus itsonWindowFocusChangedmethod will be called. Use that to set a variable you can read.