Back to parent activity

5

In manifest.xml I have the following:

    <activity
        android:name="ActividadA">
    </activity>

    <activity
        android:name="ActividadB"
        android:parentActivityName="ActividadA">
    </activity>

There is some simple way to return to a parent activity that is not typical of:

Intent intent= new Intent(this, ActividadA.class);
startActivity(intent);
    
asked by borjis 24.10.2016 в 18:04
source

3 answers

4

The way to return to the% main Activity by Intent , is not really typical, regularly the Activity parent does not reopen with a Intent , although it can be done by:

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

On the other hand, the secondary activities are regularly opened by a Intent and these are accumulated in the Back Stack.

If you wish to return to a previous Activity, you simply end up where you are by finish(); , which destroys the Current activity.

Currently it is not good practice to stack several Activity in the Back Stack since we could have mainly problems with memory, for this function we created the Fragments which are opened within an Activity without having to store different Activity in the Back Stack, it would be an incorrect design to continue using several Activity and to be stacked one after the other.

    
answered by 24.10.2016 / 20:32
source
1

You can use the function finish() which will call the method onDestroy of your Actividad current. That is, if you call an Activity from your Parent Activity and use this function from the Child Activity, you will return to the Parent Activity again.

    
answered by 24.10.2016 в 18:07
1

If in manifest.xml you specify the parentActivityName you can call navigateUpFromSameTask of NavUtils

NavUtils.navigateUpFromSameTask(this);

Using that, it has the peculiarity that when it returns to ActividadA it recharges again.

Look at the following entries:

answered by 24.10.2016 в 18:30