gpt4 book ai didi

Android PendingIntent 不启动 Activity

转载 作者:太空狗 更新时间:2023-10-29 15:10:56 24 4
gpt4 key购买 nike

我正在创建一个使用 Google GCM 服务的应用程序。

所以我定义了这个函数:

@Override
protected void onMessage(Context context, Intent intent)

onMessage 调用了一个函数,这是部分代码:

 Intent notificationIntent = new Intent(context,ShowMess.class);
notificationIntent.putExtra("id",current_id);
notificationIntent.putExtra("cat", cat);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notificationManager.notify(id, notification);

如果我向自己发送消息(使用 AsyncTask)但快速关闭应用程序(后退按钮),下一条消息将不会启动 Activity (ShowMEss.class),您认为这是为什么?

再见

谢谢

最佳答案

您上面的代码没有注册通知。您是否缺少代码中的以下部分?

    NotificationManager notificationManager = 
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(0, notification);

关于Android PendingIntent 不启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16572689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com