Alex
Alex

Reputation: 191

Android sdk activity flow

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

Upvotes: 1

Views: 141

Answers (2)

Aurélien Guillard
Aurélien Guillard

Reputation: 1203

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.

Upvotes: 2

Alexander
Alexander

Reputation: 48272

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.

Upvotes: 1

Related Questions