gpt4 book ai didi

android - 从 BroadcastRecevier 启动 AlertDialog 时在后台显示当前 Activity

转载 作者:行者123 更新时间:2023-11-29 02:01:46 27 4
gpt4 key购买 nike

我有一个半透明的 AlertDialog 设置来显示用户是否收到短信。它是从广播接收器启动的。

用户只会收到这种“紧急”类型的消息,前提是发件人将其设置为此类消息并且用户启用了这种类型的中断。

我有一个小问题,因为如果我的应用程序正在运行,我的背景就是我的应用程序最后停止的地方。我获取背景以显示用户“当前正在做的事情”的唯一方法是完全关闭我的应用程序。

有没有人在使用半透明背景的 AlertDialogs 时遇到过类似的问题?

这是我开始 Activity 的方式;

Intent i = new Intent(context, LayoutStartActivity.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

这是我的警报对话框的精简版

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(holder);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
finish();
}
});

谢谢

最佳答案

在 AndroidManifest.xml 中设置任务亲和性,以便它在最近堆栈上作为唯一进程运行。

例子

<activity android:name=".LayoutStartActivity"
android:theme="@style/Theme.Light"
android:taskAffinity="com.example.standAlone">

关于android - 从 BroadcastRecevier 启动 AlertDialog 时在后台显示当前 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12308860/

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