Imagine you have the following sequence of activities:
Activity A -> Activity B -> Activity C
When you are on Activity C, pressing the native back button, takes you to Activity B. Now what is the state of Activity C? Is it still in memory or it has been finished?
If it is still in the memory, is there a way to resume the activity? Other than starting another instance of this activity...
I should add that this is the standard case where you do not use any flags including: FLAG_ACTIVITY_CLEAR_TOP
However, when the back button is pressed, the activity is destroyed, meaning, the temporary data is lost during this call.
Instead if the Home button is pressed, the app moves to the Stopped state, still running in the background. Clearing all the apps with the Clear All button may or may not improve the overall performance because there might be no apps running in the background.
In order to check when the 'BACK' button is pressed, use onBackPressed() method from the Android library.
In Android we can change the default behaviour of the any activity like keypress, back button press, swap left swap right, to do Disable Back Press we need to override default functionality of onBackPressed() or onKeyDown() method in Activity class.
Default behavior is that when you press hardware "back" button, current activity will be removed from the backstack and activity "destroy" sequence will be initiated. From that moment you should not rely on the fact that it might be somewhere around - it is all up to Android to decide when does it actually kill this activity.
What my previous investigations show is that victim's onDestroy()
will be called only when new activity is done loading and is idle.
You can specify android:launchMode="singleInstance"
for your activity in Manifest. This will ensure that only one instance of activity is created at the time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With