如果我的应用获取新信息,我会收到通知。
但是当我点击通知时,它会重新打开活动。
我只有一个活动正在运行,所以有没有办法从同一个应用程序中关闭所有其他活动,所以我只是将它放在oncreate中并且他已经消失了......
问题在于,当应用程序不在顶部时,应该继续进行计时器事件,但每次创建新活动时,都会创建一个新计时器,因此相同的通知会被发送两次让我被判两个我每次获得新信息时都会...
这是我创建通知的地方,我想我必须在那里搜索,例如“cleartop”或“singletop”我看到谷歌搜索但没有工作..
Intent resultIntent = new Intent(this, typeof(QuestionsSession));
resultIntent.PutExtra ("targeturl", targeturl);
//resultIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop);
resultIntent.SetFlags (ActivityFlags.ClearTop);
TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(QuestionsSession)));
stackBuilder.AddNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
// Build the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.SetAutoCancel(true) // dismiss the notification from the notification area when the user clicks on it
.SetContentIntent(resultPendingIntent) // start up this activity when the user clicks the intent.
.SetContentTitle("Button Clicked") // Set the title
.SetNumber(TagsCount) // Display the count in the Content Info
.SetSmallIcon(Resource.Drawable.Icon) // This is the icon to display
//.SetContentText(Java.Lang.String.Format("There are {0} new questions.",TagsCount)); // the message to display.
.SetContentText(string.Format("There are new questions.")); // the message to display.
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
Vibrator v = (Vibrator)GetSystemService (Context.VibratorService);
// Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.Vibrate(1000);
// Finally publish the notification
NotificationManager notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
notificationManager.Notify(1000, builder.Build());
答案 0 :(得分:2)
您可以将android:launchMode="singleTask"
添加到清单文件中的activity-tag。如果活动再次打开,它将把背景中的一个带到前面。
当活动不可见时,计时器不会停止。