Notification intent is not launched in corner cases
Here's my scenario:
- I show a notification that is not clearable (
FLAG_NO_CLEAR
), - I set a pending intent that launches an
Activity
, - In the launched
Activity
, the user presses something and I launch anotherActivity
, - Clicking on the notification again does not start/show the
Activity
in the pending intent, which is very annoying. I would like the initialActivity
to be either re-launched or brought to the front. However, I can't seem to be able to achieve this.
Relevant code for notification:
Intent i = new Intent(this, RemindersActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 开发者_开发技巧the docs say this is required
PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
n.setLatestEventInfo(this, getString(R.string.app_name), text, pi);
After that, it's just normal startActivity()
(at step 3). Here's what I get in logcat:
I/ActivityManager( 147): Starting activity: Intent { flg=0x10000000 cmp=my.package/my.package.RemindersActivity bnds=[0,387][480,483] }
W/InputManagerService( 147): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@45a33fc8
Any ideas on how to fix this? The only one that comes to my mind is to use a broadcast intent instead of an activity intent (and launch the activity from the receiver), but I'm not even sure that would work.
However, I can't seem to be able to achieve this.
Try adding FLAG_ACTIVITY_REORDER_TO_FRONT
, or the combination of FLAG_ACTIVITY_CLEAR_TOP
and FLAG_ACTIVITY_SINGLE_TOP
, to the Intent
.
精彩评论