Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get parameters from the intent used for onResume()

I'm using a LocalActivityManager to have activities in different tabs, when I switch from a tab to another one, I start the Activity corresponding to the tab selected. My problem is simple :

if I click on tab 1, I create intent11 and the first time, the method onCreate(Bundle emptyBundle) of Activity1 is called. If I click on tab 2, I create intent2 and the method onCreate() is called. Then, when I click on tab1, I create intent12 , the method onCreate(Bundle emptyBundle) is not called but onResume() is called (normal behavior).

I put special extras in the intent11 and intent12 to create Activity1, so I access it using getIntent().getExtras().

My problem is : the second time I go to the tab1, the intent12 is used to start the Activity, but the result of getIntent() is still intent11. So I can't retreive the extras set in intent12, I can only retreive the extras set in intent11.

What am I doing wrong ? Should I avoid putting extras() in the intents ? Thank you.

Thank you.

PS : for the moment, I set a special flag to my intent to force to call onCreate(), but I'm sure it's not the good way of doing it.

like image 367
user860302 Avatar asked Jul 26 '11 15:07

user860302


2 Answers

I believe what you are looking for is here: https://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29

onNewIntent(Intent newIntent) allows you to override the previous intent that was used to create/resume the app with the newest intent.

like image 187
EmCo Avatar answered Sep 28 '22 06:09

EmCo


In Xamarin.Android / Monotouch I just added the following method to my Activity and it worked smoothly.

    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);
        Intent = intent;
    }

The principle should work fine also in Native Android.

like image 26
Daniele D. Avatar answered Sep 28 '22 05:09

Daniele D.