我试图使用以下代码在我的应用程序中显示一条 toast 消息。
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Do you want to continue?");
alert.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try{
//This code generates an Activity Not Found exception
}
catch(ActivityNotFoundException e) {
System.out.println("Activity Not Found Exception Raised");
Toast.makeText(getBaseContext(), "Activity Not Found", Toast.LENGTH_LONG).show(); // For the context I tried using getBaseContext, ActivityName.this also
}
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
但此消息仅在少数设备上显示。我已经在 Android 版本 4.2.2 的 HTC One X 上测试了这段代码,该代码可以正常工作。
如果我在同样具有 Android 4.2.2 的 Micromax A63 上测试相同的代码,但它不起作用。
我在互联网上搜索过此类错误,它们大多与设置菜单中的应用程序通知禁用选项有关。但我的应用程序通知没有被禁用。
EDIT
我正在做一个AlertDialog
有人可以帮我解决这个问题吗?
如果您还没有弄清楚这一点,请确保您没有禁用相关应用程序的通知;这也会禁用 toast。
https://code.google.com/p/android/issues/detail?id=35013
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)