This topic is continue of this: Android. How to start activity without creating new one?
I have read that activities are destroyed when to click BACK button.
They can be not destroyed when to move deeper to stack and then call activities back. using android:launchMode="singleTask"
for example
is it possible that activities to not be destroyed when I click button BACK and then run activity again?
exit(); or finish(); it exit full application or all activity.
The default implementation of the back button is the finish the current activity. You may however intercept that key press and do whatever you wish with it. For instance, instead of finishing your current activity, you could "bring up" the previous activity and thus making it seem as if the normal implementation is at hand.
To intercept the back button press: Android: intercepting back key
And to start your previous activity without creating a new one every time:
Intent i = new Intent(this, PreviousActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
In Kotlin 1.2:
val intent = Intent(this, RepairListActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
startActivity(intent)
Good luck.
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