【发布时间】:2011-11-18 21:47:12
【问题描述】:
我正在尝试从服务发送通知,并且成功发送(通知确实显示在状态栏上)。 但是,在单击通知以观看活动后 - 我将返回移动主屏幕。此外,我注意到在调试模式下我没有达到活动的“onCreate”方法。
这是我的一段代码: 服务代码:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int icon = R.drawable.notificationicon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, NotificationsActivity.class), 0);
notification.setLatestEventInfo(this, "My notification","Hello World!", pendingIntent);
notificationManager.notify(1, notification);
活动代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(dialogLayout);
}
【问题讨论】:
-
AndroidManifest.xml 中的 NotificationActivity 类是否定义良好? (你能粘贴你的 AndroidManifest 吗?)
标签: android android-layout android-emulator android-service android-ui