gpt4 book ai didi

java - 单击通知后不显示警报对话框

转载 作者:行者123 更新时间:2023-12-02 04:27:30 26 4
gpt4 key购买 nike

我正在尝试执行以下操作:

我的应用程序有一个 AsyncTask,它最终创建一个 AlertDialog 来请求用户插入代码。当应用程序位于前台时,可能会发生这种情况,因此我启动一个通知来通知用户,我的想法是,一旦用户单击该通知,就会显示带有 AlertDialog 的主要 Activity 。

然而,发生的情况是,一旦用户单击通知,则仅显示 AlertDialog 应该显示的 Activity ,并且我收到可能由对话框引起的 WindowLeaked 异常。

这是我用来启动通知的代码(来自 AsyncTask 的 onProgressUpdate 方法):

public void launch_notification(){
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(context.getString(R.string.opening_request_notification_title))
.setContentText(context.getString(R.string.opening_request_notification_text));
/* The intent must be created with an specific content and then frozen to be used
later using a pending intent.
*/
Intent notificationIntent = new Intent(context, Main.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

任何想法都会受到欢迎。非常感谢:)

最佳答案

最好创建一个单独的 Activity(例如 DialogActivity)并在 list 中为 DialogActivity 设置。

关于java - 单击通知后不显示警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31948636/

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