尝试在 Activity 有意打开后制作 Toast
我有一个活动由两个意图调用,一个是在简单的菜单选择后调用,另一种是在删除数据库中的项目后由意图调用。但是,我想在被调用的活动中显示一个小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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过
if ("calling".equals(check))
而不是if(check == "calling")
?编辑:
尝试Toast.makeText(上下文,文本,持续时间).show();
Have you tried
if ("calling".equals(check))
instead ofif(check == "calling")
?EDIT:
try
Toast.makeText(context, text, duration).show();
您必须调用 toast 的 show 方法,否则 toast 将不会显示。
you have to call show method for toast until otherwise toast will not display.