0
PendingIntent我有点迷失。PendingIntent域中丢失
据我所知,这是一个授予操作系统执行后续(因此未决)操作的令牌。
我有一项启动服务的活动。该服务偶尔会创建通知。 我最想做的就是把活动放在最前面。
我不确定我在哪里以及如何创建以及向谁发送PendingActivity。
- 如果我在Activity中创建它,我需要将它发送到服务 - 如何?
- 如果我在服务中创建它,上下文将如何调用该活动?这些都一样吗? - 尽管这些与操作系统的工作方式相同,但对我来说并不适用。
这里有一些代码行
这不是BTW工作StartService得到一个意向。 此代码是在我的活动
Intent intent = new Intent(this, NeglectedService.class);
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this,
0,
intent,
PendingIntent.FLAG_ONE_SHOT);
startService(contentIntent);
所以,正确的是
Intent intent = new Intent(this, NeglectedService.class);
startService(contentIntent);
所以我觉得做我的服务挂起的意图,但这并没有为我工作,我我不知道如何重用/使用意向
Notification notification = new Notification(R.drawable.icon,
extra,
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this,
0,
intent, // not sure what intent to use here !!!!
PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.FLAG_INSISTENT;
mNotificationManager.notify(id, notification);
找到了答案。 这似乎更多的试验和错误。 需要做什么,是在意图中使用Neglected.class。它的工作原理,我仍然不明白为什么以及如何。 我会玩田野。 Intent intent = new Intent(this,Neglected.class); – Saariko
旧的habbits我猜“:-) 谢谢 – Saariko