在我的应用程序后台服务启动,并从该服务,我想设置状态栏通知,该服务已经启动下面是代码:处理状态栏通知
Context context = getApplicationContext();
String ns = Context.NOTIFICATION_SERVICE;
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(MyService.this, MyClass.class);
notificationIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(1, notification);
通知显示在状态栏,但我只点击那个MyClass.class没有被解雇。并且在日志猫中它显示 “输入管理器服务窗口已经集中忽略了焦点...”
因此PLZ提供了解决方案。
在此先感谢
'FLAG_UPDATE_CURRENT'只影响其他'PendingIntents'。 'onNewIntent()',虽然是很重要的 - 如果该活动已经在运行,它不会收到'的onCreate()',因为它已经被创建。 – CommonsWare 2010-03-08 15:16:52