摩托罗拉 Xoom 上的 Android 3.0.1 中不显示共享 Toast
我在不同的 Activity
之间使用共享的 Toast
,以便仅显示最新消息,并立即丢弃任何以前的消息。我将代码放入自定义 Application
对象中:
public class GameApp extends Application {
private Toast mToast;
@Override
public void onCreate() {
super.onCreate();
mToast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
}
public void displayToast(int textId) {
displayToast(getText(textId));
}
public void displayToast(CharSequence text) {
mToast.cancel();
mToast.setText(text);
mToast.show();
}
}
Toast
显示在我的 1.6
、2.2
和 < code>3.0 模拟器。但是当我从市场下载已发布的应用程序时,它仅显示在我的 G1 (CyanMod 6.1
) 上,而不显示在 Xoom (3.0.1
) 上。我尝试使用 USB 调试连接 Xoom,但 LogCat
中没有显示任何相关内容。
在此之前,我曾经以传统方式(即通过Toast.makeText())进行Toast,并且一切都按预期工作。
我的上述代码是否存在任何潜在问题,或者这可能是 Xoom 中的错误?这是我的应用的链接,以防您想测试它。当您在主屏幕中单击Today
、Progress
时,Toast
应该会显示。我很感激任何帮助。非常感谢 :)
I use a shared Toast
across different Activities
in order to only show the latest message, immediately discarding any previous ones. I put the code in the custom Application
object:
public class GameApp extends Application {
private Toast mToast;
@Override
public void onCreate() {
super.onCreate();
mToast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
}
public void displayToast(int textId) {
displayToast(getText(textId));
}
public void displayToast(CharSequence text) {
mToast.cancel();
mToast.setText(text);
mToast.show();
}
}
The Toast
showed up on my 1.6
, 2.2
, and 3.0
emulators. But when I downloaded the released app from the Market, it only shows on my G1 (CyanMod 6.1
) but not Xoom (3.0.1
). I tried connecting the Xoom with USB debugging, but nothing relevant showed up in LogCat
.
Prior to this, I used to do Toast
s the conventional way (i.e. via Toast.makeText()
) and that worked on everything as expected.
Could there be any potential problem with my above code, or could this be a bug in the Xoom? Here is the link to my app, in case you want to test it. The Toast
should show up when you click Today
, Progress
in the Main screen. I appreciate any help. Thank you very much :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定,但 motorola 使用的 sdk 可能不同..并且 mToast.cancel() 可能会做一些可怕的事情..所以你尝试过这个吗..
i'm not sure but the sdk that motorola uses may be different.. and
mToast.cancel()
could be doin something terrible.. so have you tried this..这是因为
mToast.cancel();
可能会关闭正在显示的 Toast,或者如果尚未显示则不显示它。请创建新的 Toast当用户单击按钮时对象。并保留之前的Toast对象引用。下次用户单击按钮时,取消之前的 Toast 对象并再次创建新的 Toast。
This is because that
mToast.cancel();
may close the toast if it's showing, or don't show it if it isn't showing yet.Please create new Toast object when users click buttons. And keep the previous Toast object reference. Next time when user click buttons, cancel the previous Toast object and create new Toast again.