简体   繁体   English

Android使用Intent启动活动

[英]Android starting activity using Intent

In my app I am using Notification . 在我的应用中,我正在使用Notification When user clicks on this Notification than starts my application(if it not running) or dialog is showing. 当用户单击此通知时,将启动我的应用程序(如果未运行)或对话框。 In the activity I do checking 在活动中我会检查

    intent = getIntent();
    if (intent.getExtras() != null) {
        mPrice = getIntent().getExtras().getString("price");
        showDialog(mPrice);
    }

Everything work good, except when my activity started via Notification, every time when I exit from app using back button and start app again it shows me dialog. 一切正常,除了通过通知启动我的活动时,每次我使用后退按钮退出应用程序并再次启动应用程序时,都会显示对话框。 I have tried remove this Extras using getIntent().getExtras().remove("price") but it doesn't work. 我尝试使用getIntent().getExtras().remove("price")删除此Extras,但是它不起作用。 How to fix this, that dialog shows only one time if clicked on the Notification? 如何解决此问题,如果单击通知,该对话框仅显示一次?

getExtras creates a copy of the extras. getExtras创建附加内容的副本。

You need to use 您需要使用

getIntent().removeExtra("price");

Check that the getString actually has returned a value, like this: 检查getString实际上已经返回了一个值,如下所示:

intent = getIntent();
if (intent.getExtras() != null) {
    mPrice = getIntent().getExtras().getString("price");
    if (mPrice != null) showDialog(mPrice);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM