如果我的应用程序获得新信息,我会发送通知。
但是,当我单击通知时,它会重新打开活动。
我只有一个活动在运行,所以有没有办法从同一个应用程序中关闭所有其他活动,所以我只是把它放在 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());