1

Can someone help me replicate the following scenario:

I'm having a activity A with some specific tasks from which the app goes to activity B. When the user goes to B and presses back the app should close (maybe meaning that activity A performed finish()). But in some cases the app (not on the user action) goes back to Activity A, with the state preserved to when it went to B. The thing is that the app can never know if it should preserve activity A to be re-displayed later or not. Hope I made it clear. Many thanks

2 Answers 2

2

You can start the Activity B with startActivityForResult() and in function of the result, when we come back to the activity A, Activity A finish() himself or not.

2
  • Yes, but instead of exiting the app it will pop to A and then exit. I don't know if it's the best approach. Still searching for another one. But, it's a solution, many thanks.
    – Alex
    Oct 20, 2012 at 8:50
  • The Activity A will always be on the stack when you will launch the activity B, so, it will take no time to popup the activity A, it will very fast and finish instantly, you will never have the time to see the activity A or maybe on some very low configuration phones... Oct 23, 2012 at 8:12
1

You can populate your Activity A every time in its onResume(). For persistence you can use SharedPreferences.

You can setup a BroadcastReceiver in Activity A which will call finish() for Activity A upon receiving a message. In the Activity B just before you close you then send that message to Activity A's broadcast receiver.

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.