本文介绍了如何设置单击侦听器通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的code启动时,启动服务通过AlarmManager通知:
I am using the following code to launch a notification when a Service is started Via 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);
我如何设置一个意图为这个项目,这样当用户点击它,它会推出一定的活动?
How do I set an intent for this item so that when the user clicks on it, it would launch a certain activity?
推荐答案
您基本上需要将活动类作为你的意图的一部分到你的PendingIntent。目前你的意图是空的。要重定向到新的活动,它应该是:
You basically need to put the Activity class as part of your intent into your PendingIntent. Currently your Intent is empty. To redirect to new activity, it should be:
// 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);
这篇关于如何设置单击侦听器通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!