Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android getIntent() returns same intent in onResume() each time. how to clear int field in a bundle?

Tags:

android

I am working on app that uses getIntent() to read bundled information. I would like to set one of the bundle fields to null, so that on subsequent resumes a modified intent is received, but I keep getting the same intent back from getIntent(). I notice that after the back key is pressed than a new intent is produced, but not otherwise.

 intent.getExtras().getInt("FLAG_FIELD") returns 1
 intent.getExtras().setString("FLAG_FIELD", null);

but when the Activity resumes again getInt() still returns a value instead of null. Not sure than how to clear a Int field in a bundle.

Update just tried:

intent.getExtras().putInt("FLAG_FIELD, -1); 

This also does not work. Looks like intent from getIntent() cannot be changed.

Update: onResume() gets called in the debugger 3 times in a row before the activity becomes visible? So even if I set a flag here it seems that its hard to change state because I cannot tell which resume() call is the last one before an actual display.

like image 554
Android Developer Avatar asked Dec 11 '12 23:12

Android Developer


1 Answers

You can override onNewIntent() and change the extras there. Here is the documentation for that. After this method, your onResume() will be called which I think is what you are after

like image 55
codeMagic Avatar answered Sep 16 '22 15:09

codeMagic