Get parameters from intent used for onResume ()

I use the LocalActivityManager to work in different tabs, when I switch from tab to another, I launch an Activity corresponding to the selected tab. My problem is simple:

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

I put special additions in intent11 and intent12 to create Activity1 , so I access it with getIntent().getExtras() .

My problem: the second time I switch to tab1, intent12 used to start the Activity , but the result of getIntent() is still intent11 . Thus, I can not postpone the additional settings set in intent12 , I can only restore the additional settings set in intent11 .

What am I doing wrong? Should I avoid placing additional functions () in intent? Thanks.

Thanks.

PS: at the moment I'm setting a special flag for my intention to force onCreate () to be forced, but I'm sure this is not the best way to do this.

+6
source share
3 answers

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

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

+6
source

no, you should be able to still add additional features, but I wonder if the additional components will be “overwritten” when creating new intentions, so I suggest trying the following:

Put your add-ons in the kit for the first intention that you create, and then before creating the next intention, install your kit for what might be in the kit by doing

 Bundle bundle = getResultExtras(false); 

Then you can create your new intention, then when you are ready to pull your data out of the package you can do

 Bundle bundle = getResultExtras(false); 

and then get your data, as usual, from the kit, just make sure that the add-ons you added to Intent1 do not have the same key name as the additional functions that you added to Intent2

hope this helps.

if you need more specific help, it might be helpful to post your code.

+1
source

In Xamarin.Android/Monotouch, I just added the following method for my activity, and it worked smoothly.

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

The principle should work fine on Native Android as well.

+1
source

Source: https://habr.com/ru/post/893605/


All Articles