8

我显示了一条通知。现在我希望发生这种情况:

当我点击通知时,我想打开一个对话框,我只打印 1 个字符串。

现在,当我创建通知时,我无法解决,在这里做什么:

...
Intent notificationIntent = new Intent(context, {how to open dialog}); 
...

然后是 1 个按钮,例如“确定”,它将关闭对话框。

请帮我。

谢谢。

4

1 回答 1

6

我在我的一个应用程序中正是这样做的。在通知中,您需要执行以下操作:

PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
    new Intent("com.yourcompany.yourapp.MAINACTIVITY").putExtra("fromnotification", true);

在你的主要活动中使用 onResume() 方法来检查这个额外的:

@Override
    public void onResume()
    {
            super.onResume();

            if (getActivity().getIntent().getBooleanExtra("fromnotification", false) == true)
            {
                    getActivity().getIntent().removeExtra("fromnotification");
                    startActivityForResult(
                                    new Intent("com.yourcompany.yourapp.DIALOGACTIVITY"), 123);
            }

    }

这段代码显示了一个带有对话框样式的活动,但是它没有理由不能在 if 语句中创建一个对话框。

于 2012-06-05T18:34:11.283 回答