在Android中使用通知,将活动带到前台
我提出了一个通知。我想要的是,当用户单击通知时,我的活动将显示在最前面,而不创建它的新实例。 为此,我添加了标志REORDER_TO_FRONT,但当我单击通知时,仍然调用oncreate而不是onNewIntent 这是我的密码-在Android中使用通知,将活动带到前台,android,android-activity,notifications,Android,Android Activity,Notifications,我提出了一个通知。我想要的是,当用户单击通知时,我的活动将显示在最前面,而不创建它的新实例。 为此,我添加了标志REORDER_TO_FRONT,但当我单击通知时,仍然调用oncreate而不是onNewIntent 这是我的密码- int icon = R.drawable.android; long when = System.currentTimeMillis(); CharSequence text = "new message";
int icon = R.drawable.android;
long when = System.currentTimeMillis();
CharSequence text = "new message";
CharSequence contentTitle = stanza.getFrom(); // message title
CharSequence contentText = stanza.getBody(); // message text
Intent notificationIntent = new Intent(context, ChatBox.class);
notificationIntent.putExtra("buddyid",stanza.getFrom());
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, text, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1,notification);
你有没有试过:
Intent.FLAG_ACTIVITY_CLEAR_TOP
使用您的notificationIntent.addFlag() 你试过:
Intent.FLAG_ACTIVITY_CLEAR_TOP
使用您的notificationIntent.addFlag() 我的解决方案是制作一个广播接收器,监听通知触发的广播动作。所以基本上:
对此,我的解决方案是制作一个广播接收器,用于侦听通知触发的广播操作。所以基本上:
我试过了,现在,同样的结果,oncreate被调用了。现在试试这个。意图=新意图(上下文,ChatBox.class);intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK|intent.FLAG_ACTIVITY_SINGLE_TOP);在manifest中,添加到您的活动android:launchMode=“singleTop”我想这会对您有所帮助。我尝试过,现在,相同的结果是,oncreate被调用。好的。现在试试这个。意图=新意图(上下文,ChatBox.class);intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK|intent.FLAG_ACTIVITY_SINGLE_TOP);在清单中添加到您的活动android:launchMode=“singleTop”我想这会对您有所帮助。访问对我来说很好!访问对我来说很好的网站!