Reputation: 389
What I want to do is -
My application is in running state and I pause the app i.e. 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);
Upvotes: 0
Views: 678
Reputation: 798
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);
Upvotes: 1