Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigating Up to an activity that expects extras

Tags:

android

I have Activities A, B, and C in my app and they flow in that order. If I implement the Up button in C, I want it to go back to B. The code stub that Eclipse generated is this:

@Override
public boolean onOptionsItemSelected(MenuItem item) 
{
    switch (item.getItemId())
    {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-vs-back
            //
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }

    return super.onOptionsItemSelected(item);
}

However, B expects extras to be passed from A in its onCreate method. The relationship between B and C is that C allows the user to set some settings that affect how B is displayed. I'm currently handling saving the changes in C in onPause(). Should I just finish() C when user presses Up instead of calling navigateUpFromSameTask(this)?

like image 932
ashishduh Avatar asked Jun 21 '13 14:06

ashishduh


1 Answers

If you're going to be returning from C back to B your activity will be created again, if you use standard launch mode. onSaveInstanceState will not (reliably) work.

Declare the launch mode of your activity B as:

android:launchMode="singleTop"

in your AndroidManifest.xml, if you want to return to your activity. See docu and an explanation here.

like image 108
yonojoy Avatar answered Oct 19 '22 02:10

yonojoy