小编Gab*_*aby的帖子

如何在单击通知时启动活动?

我的Android应用程序中有一个奇怪的问题.我已完成通知,我想在点击通知时启动新活动.问题是当我点击通知时没有任何反应,我不知道问题出在哪里?任何人都可以帮助我吗?这是我的代码:

notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence NotificationTicket = "Notification";
CharSequence NotificationTitle = "Notification";
CharSequence NotificationContent = "Test";
long when = System.currentTimeMillis();

Notification notification = new Notification(R.drawable.icon,
NotificationTicket, when);

Context context = getApplicationContext();

Intent notificationIntent = new Intent(this, ShopsOnMap.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);

notification.setLatestEventInfo(context, NotificationTitle, NotificationContent, contentIntent); 
notificationManager.notify(NOTIFICATION_ID, notification);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP); 
Run Code Online (Sandbox Code Playgroud)

notifications android android-activity

4
推荐指数
1
解决办法
6912
查看次数

标签 统计

android ×1

android-activity ×1

notifications ×1