开发者

Notification intent is not launched in corner cases

Here's my scenario:

  1. I show a notification that is not clearable (FLAG_NO_CLEAR),
  2. I set a pending intent that launches an Activity,
  3. In the launched Activity, the user presses something and I launch another Activity,
  4. Clicking on the notification again does not start/show the Activity in the pending intent, which is very annoying. I would like the initial Activity 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜