gpt4 book ai didi

android - 如何关闭所有基础 Activity

转载 作者:行者123 更新时间:2023-11-29 00:26:24 29 4
gpt4 key购买 nike

如果我的应用获得新信息,我会收到通知。

但是当我点击通知时它会重新打开 Activity 。

我只有一个 Activity 在运行,所以有没有办法关闭同一个应用程序的所有其他 Activity ,所以我只是把它放在 oncreate 中,他就走了..

问题是有一个计时器事件应该在应用程序不在顶部时继续进行,但每次我创建一个新 Activity 时,都会创建一个新计时器,所以相同的通知会发送两次,让我收到两次警报每次我得到新信息时..

这是我创建通知的地方,我想我必须在那里搜索它,例如我看到谷歌搜索但没有用的“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());

最佳答案

您可以将 android:launchMode="singleTask" 添加到 list 文件中的 Activity 标签。如果 Activity 再次打开,它将把后台的那个带到前台。

当 Activity 不可见时,计时器不会停止。

关于android - 如何关闭所有基础 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19030109/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com