简体   繁体   中英

One activity is in background and other in foreground ,

What I want to do is -

My application is in running state and I pause the app ie . move it to the background. And user locks the screen and then unlocks it, so for ACTION_USER_PRESENT i want to start an advertisement activity from my app. But the activity in background should be there in the background and the one shown in the foreground is handled seperately . But if the click option from foreground activity is performed , it should close the foreground activity and launch the background activity.

Problem is - When the User present intent is fired, then the new activity i launch , and restarts the activity that have been paused. But i dont want this, is the app was in background. Only the activity newly started should be shown in the front.

From the receiver i am doing this to start the new activity :

 Intent i = new Intent(context, MyAd.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

To start a quite new Activity

Intent i = new Intent(context, MyAd.class);
context.startActivity(i);

Because FLAG_ACTIVITY_NEW_TASK will resume the old opened activity from the stack.

FLAG_ACTIVITY_NEW_TASK If set, this activity will become the start of a new task on this history stack.

https://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK

And if you only want to keep an Activity instant in Activity Stack. Use

i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM