我对PendingIntent有点失落。
据我所知,这是给操作系统执行稍后(因此待处理)操作的令牌。
我有一项推出服务的活动。该服务偶尔会创建一个通知。 我最想做的就是将活动带到前线。
我不确定我在哪里以及如何创建以及向谁发送PendingActivity。
以下是一些代码行
这不起作用btw StartService获取Intent。 此代码在我的活动中
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);
答案 0 :(得分:1)
解决 需要做的是使用intent中的Neglected.class。