Android的多个实例
我在与Android的通知,每当我点击通知evrytime我必须再次拨打同一活动的一个问题,但据我想到了新的活动被称为但是previous也运行在后端,由于这我code被一次又一次地运行(becoz多个实例)
I am in a problem with the notifications in android, whenever I click the notification evrytime I have to call the same activity again, but as far as I am thinking the new activity is called but the previous is also running in the backend, due to which my code is running again and again ( becoz of multiple instances )
请帮助我如何每次点击一个通知时间解决或关闭多个实例。
Please help me how to resolve or close multiple instances each time a notification is clicked.
code
公共无效notificationforChat(CharSequence的消息,字符串toJid,诠释notificationID){
public void notificationforChat(CharSequence message,String toJid, int notificationID) {
int notificationCount = 1;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = message;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
//notification.number = notificationCount++;
Context context = getApplicationContext();
CharSequence contentTitle = "Chat";
CharSequence contentText = message;
Intent notificationIntentforChat = new Intent(this, UserChatActivity.class);
notificationIntentforChat.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntentforChat.putExtra("userNameVal", toJid);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntentforChat, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_ALL;
mNotificationManager.notify(notificationID, notification);
}
感谢
怎么样启动活动的android:launchMode =singleInstance
模式或 Android的:launchMode =singleTop
模式。我认为这会有所帮助。
What about starting the activity in android:launchMode="singleInstance"
mode or android:launchMode="singleTop"
mode. I think this helps.