通过AlarmManager启动服务时,我使用以下代码启动通知:
nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "App";
CharSequence message = "Getting Latest Info...";
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
Notification notif = new Notification(R.drawable.icon,
"Getting Latest Info...", System.currentTimeMillis());
notif.setLatestEventInfo(this, from, message, contentIntent);
nm.notify(1, notif);
如何设置此项目的意图,以便当用户点击它时,它会启动某个活动?
解决方法:
您基本上需要将Activity类作为意图的一部分放入PendingIntent中.目前你的Intent是空的.要重定向到新活动,它应该是:
// This line of yours should contain the activity that you want to launch.
// You are currently just passing empty new Intent()
PendingIntent contentIntent =
PendingIntent.getActivity(this, 0, new Intent(this, MyActivity.class), 0);