【问题标题】:Show current Activity in background when launching AlertDialog from BroadcastRecevier从 BroadcastReceiver 启动 AlertDialog 时在后台显示当前活动
【发布时间】:2012-09-06 21:44:55
【问题描述】:

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

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

我有一个小问题,因为如果我的应用程序正在运行,我的背景就是我的应用程序上次停止的地方。我让背景显示用户“当前正在做什么”的唯一方法是完全关闭我的应用程序。

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

这是我开始活动的方式;

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();
        }
    });

谢谢

【问题讨论】:

  • 你试过用线程吗?

标签: android broadcastreceiver android-alertdialog


【解决方案1】:

在 AndroidManifest.xml 中设置任务关联性,使其在最近堆栈上作为唯一进程运行。

例子

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

【讨论】:

  • 我有一个透明主题,但 taskAffinity 标签非常有用。你是最棒的 !谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-25
  • 2020-04-25
  • 1970-01-01
  • 1970-01-01
  • 2018-07-31
  • 1970-01-01
相关资源
最近更新 更多