来自广播接收器的 Toast 消息
我有一个广播接收器,我正在尝试显示一条来自它的 Toast 消息,这可能吗? 此代码不显示 toast,但会在 logcat 中打印日志消息。我正在做一些愚蠢的事情或者我的问题是什么?
@Override
public void onReceive(Context context, Intent intent) {
Log.v("log", "this is shown");
Toast.makeText(context, "this is not shown" , Toast.LENGTH_LONG);
}
I have a broadcast receiver and I am trying to show a toast message from it, is this possible ?
This code doesn't show the toast but it print the log message in the logcat. Is there some idiotic thing I am doing or what is my problem ?
@Override
public void onReceive(Context context, Intent intent) {
Log.v("log", "this is shown");
Toast.makeText(context, "this is not shown" , Toast.LENGTH_LONG);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调用
Toast
的show()
方法。Call the
show()
method for theToast
.您忘记在
Toast
上调用show()
..虽然我不建议从 BroadcastReceivers 创建 toast..您可能会考虑使用通知
you forgot to call
show()
on theToast
..although i would not recommend creating toasts from BroadcastReceivers.. you might consider using Notifications
使用这个
Toast.makeText(context, "this is not shown",Toast.LENGTH_LONG).show();
Use this
Toast.makeText(context, "this is not shown",Toast.LENGTH_LONG).show();