Android studio- skip activity

2

I am making an application, more to learn from mistakes than anything else, and I needed help to achieve this:

From the Main activty , I open activity2 , and from activity2 I open a activity3 , but I do not want the user to go back and enter activty2 , but jump to Main activity .

    
asked by Fernando Godoy 09.03.2017 в 01:46
source

3 answers

0

When you use the instruction:

Intent intent = new Intent(Pagina1.this, Ayuda.class);
startActivity(intent);

You add an activity to the Android activity stack. Therefore if you want to remove items from the stack, using startActivity without options is just the opposite.

To remove activities from the stack you can use:

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

You can see more information on the official Android

    
answered by 09.03.2017 / 04:15
source
1
  

From Mainactivity, I open activity2, and from activity2 I open an activity3, but   I do not want the user to go back and enter activty2, but   that jumps towards the Main activity.

This would be simple to implement, you have simply used the finish() method to close the Activity that you do not want to keep.

When you open activity3 from activity2 , you end activity2 by finish() :

Intent myIntent = new Intent(activity2.this, activity3.class);
startActivity(myIntent);
finish();

This way when the user closes activity3 will return to Mainactivty since previously ended activity2 .

    
answered by 10.03.2017 в 21:20
0

In the end I solved it like this: (I do not know if it will be the correct way but at least now it goes)

@Override
    public void onBackPressed()
    {
        // Añade más funciones si fuese necesario
        Intent intent = new Intent(Pagina1.this, Ayuda.class);  // Invoca al método
        startActivity(intent);
    }
    
answered by 09.03.2017 в 02:22