How to return between various Android activities

-2

I have a problem I hope someone can help me.

I have several activities

Main Activity, Activity 1, Activity 2, Activity3

Primal Activity let's say it's a list and activities 1 to 3 are forms, in activity3 when a save ends I need to return to the main activity, but if I use finish only return to the previous one, I do not want to use startActivity because when they give it with the "return" phone button, we would return to Activity 3.

Thank you.

    
asked by Rogelio Sanchez 16.02.2018 в 01:39
source

1 answer

1

To achieve what you want first you have to indicate that your main activity will have only one instance using the android:launchMode attribute in the manifest.xml .

For example:

<activity
   android:name="..."
   android:launchMode="singleTask"
   />

Then when you need to return to your activity, you invoke it using the method startActivity :

Intent intent = new Intent(context, MyActivity.class );
intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity( intent );

FLAG_ACTIVITY_CLEAR_TOP what it does is eliminate the stack of active activities.

    
answered by 16.02.2018 / 01:58
source