Toggle activity back and forth on Android

I start with Android and get the initial question about switching between multiple actions.

I understand that I can move between two actions by calling an intent and then returning using setResult (). I want to know how to jump between several actions. In particular, I want to learn about the life cycle of a process. I understand how each ar onCreated () action begins, but I'm not sure how to implement onResume () or onRestart () when I want to return.

So basically I have 3 actions: Activity1, Activity2 and Anctivity3.

I start with Activity1 and then call Activity2 with Intent, and Activity2 calls Activity3. Using buttons. Now I want to return to Activity1 from Activity3. I do the same too. Make an intention and call startActivity (Activity1_Intent). But this gives a runtime error.

It seems to me that I need to implement OnResume () or onRestart (), but I'm not sure how to do this. In onCreate (), I create a gridView, so when I return, do I need to do this gridView again?

If anyone can give a little explanation regarding the manual, it would be great. Thank you very much.

+7
android switch-statement
source share
2 answers

In your manifest file, set android: launchMode = "singleTop" to your Activity1.

Then to call the function Activity1:

Intent intent = new Intent(this, Activity1 .class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); 

FLAG_ACTIVITY_CLEAR_TOP: if set, and the launched activity is already running in the current task, instead of starting a new instance of this action, all other actions on top of it will be closed, and this intention will be delivered to (now from above) the old activity as a new intention.

FLAG_ACTIVITY_NEW_TASK: if set, this action will be the beginning of a new task in this history stack.

http://developer.android.com/reference/android/content/Intent.html

+7
source share

Starting with Android 4.0, you can simply set android: launchMode = "singleTask" in the manifest file, and then there is no need to write Java.

+1
source share

All Articles