尝试在 Activity 有意打开后制作 Toast

发布于 2024-11-26 23:20:46 字数 914 浏览 0 评论 0原文

我有一个活动由两个意图调用,一个是在简单的菜单选择后调用,另一种是在删除数据库中的项目后由意图调用。但是,我想在被调用的活动中显示一个小Toast,但仅当它通过删除意图打开时才显示。我想到了以下解决方案

public void intentCheck(){
    Log.d("ShowActivity","intentCheck() called");
    Bundle extras = getIntent().getExtras();
    if (extras != null){    
            String check = extras.getString("AdvancedViewActivityCall");
            if(check == "calling"){
                Log.d("ShowActivity","delete-intent succeeded");
                Toast success = new Toast(ShowActivity.this);
                success.makeText(ShowActivity.this, "Deletion succeded", Toast.LENGTH_LONG); 

            }
        }

,但它不起作用......不知何故,没有显示吐司。

编辑://我应用了 success.show();现在,但现在我得到了 RunetimeException Oo ( http://pastebin.com/Th3NY5d0 )

编辑:解决方案:<代码>Toast.makeText(上下文,文本,持续时间).show(); //似乎是eclipse提出的“静态方式”

I have an activity which gets called by 2 intents, one after a simple menu-selection and the other way by a intent after a deletion of an item in a database. However, I wanted to display in the called activity a little Toast, but only when it's opened through the intent of the deletion. I thought of following solution

public void intentCheck(){
    Log.d("ShowActivity","intentCheck() called");
    Bundle extras = getIntent().getExtras();
    if (extras != null){    
            String check = extras.getString("AdvancedViewActivityCall");
            if(check == "calling"){
                Log.d("ShowActivity","delete-intent succeeded");
                Toast success = new Toast(ShowActivity.this);
                success.makeText(ShowActivity.this, "Deletion succeded", Toast.LENGTH_LONG); 

            }
        }

but it doesn't work... somehow, no toast gets displayed.

edit:// i applied success.show(); now, but now i get a RunetimeException O.o ( http://pastebin.com/Th3NY5d0 )

edit: SOLUTION: Toast.makeText(context, text, duration).show(); //seems to be the "static way", which eclipse proposed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半透明的墙 2024-12-03 23:20:46

您是否尝试过 if ("calling".equals(check)) 而不是 if(check == "calling")

编辑:
尝试Toast.makeText(上下文,文本,持续时间).show();

Have you tried if ("calling".equals(check)) instead of if(check == "calling") ?

EDIT:
try Toast.makeText(context, text, duration).show();

偏闹i 2024-12-03 23:20:46

您必须调用 toast 的 show 方法,否则 toast 将不会显示。

success.show();

you have to call show method for toast until otherwise toast will not display.

success.show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文