I have an activity which is called if the app receives a push notification. The activity is started with FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TOP. The activity, let's call it 'A' shows UI and finishes after a while. In this point have a problem with activity stack.
Scenario:
- The app is in the background with another activity 'B'
- Then the app receives a push notification and starts Activity A.
- After related things done, the app finishes Activity A
- Then returns to Activity B and stays in the foreground even the app was in the background before the push notification is received.
After debugging, I figured out that the system calls onResume method of Activity B after finishing Activity A.
How can I do the app keep staying in background if the app started from background? Should I change intent flags of the activity A?
In your case you can achieve this in two ways
1- From manifest file with activity tag
android:noHistory="true"2- From code when you are staring the activity set flags like below
For more information checkout developers link
One other thing you can do is instead of
this.finish()in notificationActivity is to usethis.finishAffinity();. This will close the app instead coming to foreground.