Android getIntent () returns the same intention in onResume () every time. how to clear int field in package?

I am working on an application that uses getIntent () to read related information. I would like to set one of the package fields to null, so that subsequent renewals will get the changed intention, but I get the same intention back from getIntent (). I noticed that after pressing the back key, what creates a new intention, but not otherwise.

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

but when activity resumes again, getInt () will still return a value instead of zero. Not sure how to clear Int field in package.

The update just tried:

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

This also does not work. It seems that the intent from getIntent () cannot be changed.

Update: onResume () is called in the debugger 3 times in a row before the action becomes visible? Therefore, even if I set the flag here, it seems that it is difficult to change it, because I cannot determine which resume () call is the last before the actual display.

+8
android
source share
2 answers

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

+9
source share

In my case, my problem was an error with the intent flags selected. My code was not:

 notificationIntent.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)); 

Now I decided using

  notificationIntent.setFlags((PendingIntent.FLAG_UPDATE_CURRENT)); 

Yes, not the best solution, but it works

0
source share

All Articles