android - getIntent() in onResume() always returns same action, how to consume it? -
i'm showing notification intent this:
intent intentopen = new intent(this, mainactivity.class); intentopen.setaction("action_show_backup_fragment"); intentopen.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent pendingintentopen = pendingintent.getactivity(this, 0, intentopen, pendingintent.flag_update_current); notificationbuilder.setcontentintent(pendingintentopen);
as can see, action set "action_show_backup_fragment"
, when user clicks in notification, singletop mainactivity can action in onresume()
method getintent().getaction()
.
in order work had implement onnewintent()
this:
protected void onnewintent(intent intent) { super.onnewintent(intent); setintent(intent); }
so far, good, action received , can show backup view. if press home button, app goes background, , come in on 1 time again via recent apps menu, onresume()
method called 1 time again "action_show_backup_fragment"
action still there! so cannot differentiate if user clicked on notification or resuming app.
i have tried solving issue log of combinations of intent , pendingintent flags nil worked. tried calling setintent(new intent());
after using action in onresume()
onnewintent()
still gets "action_show_backup_fragment"
action next time resume app.
how can solve issue?
finally found right combination of flags intent , pendingintent:
// create pending intent open backup fragment intentopen.setflags(intent.flag_activity_single_top); pendingintent pendingintentopen = pendingintent.getactivity(this, 0, intentopen, pendingintent.flag_cancel_current);
this works while still consume intent in onresume()
setintent(null);
android android-intent android-activity android-notifications android-pendingintent
No comments:
Post a Comment