【问题标题】:Open Dialog from Notification从通知打开对话框
【发布时间】:2012-06-06 02:34:11
【问题描述】:

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

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

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

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

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

请帮帮我。

谢谢。

【问题讨论】:

    标签: android dialog notifications


    【解决方案1】:

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

    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 语句中创建一个对话框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      • 2017-05-06
      • 2022-01-23
      • 1970-01-01
      • 2015-12-30
      相关资源
      最近更新 更多