Configure "Activity" hierarchy in "Androidmanifest"

Asked

Viewed 1,369 times

3

I’m trying to figure out how to set up a Activity to return to the Activity previous in AndroidManifest?

2 answers

4


The hierarchy of Activity is configured in manifest, where we can define which navigation is expected between them:

Example:

<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".ResultActivity"
    android:parentActivityName=".MainActivity">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value=".MainActivity"/>
</activity>

In the example above, the MainActivity is defined as the predecessor of ResultActivity.

This subject is addressed in some detail in the training examples at:

Preserve Navigation when starting an Activity (English)

  • I tried to do this and my application gave crash.

  • I found this business of setting up the hierarchy of activities a little prolific, is it really necessary? From what I understand the documentation cites two possible situations when a notification is clicked, open the activity at the top of the current backstack or open in a new backstack that only contains the activity. In none of the cases I see need to specify the hierarchy, I simply click on the notification and the activity is opened at the top of the backstack or in a new backstack depending on the Intent flags that were used. taskAffinity and excludeFromRecents are of use, edge cases of navigation?

0

I didn’t understand your question properly but all the Activity'will come out of Activity MAIN, when you call the method onBackPressed() (English) she will close the current and return to which was called.

Example:

MAIN --> Activity1 --> Activity2 \/

MAIN <-- Activity1 <-- Activity2 

Move forward: new Intent(); (English)

Return: onBackPressed(); (English)

Remembering that this is already done automatically there is no need to implode the onBackPressed() unless he wanted some more function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.