在我的應用程序後臺服務啓動,並從該服務,我想設置狀態欄通知,該服務已經啓動下面是代碼:處理狀態欄通知
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