我正在尝试使用以下代码在我的应用程序中显示 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 上测试相同的代码,但它不起作用。
我在 Internet 上搜索了此类错误,它们主要是关于设置菜单中的应用通知禁用选项。但是我的申请通知没有被禁用。
编辑
我在 AlertDialog
谁能帮我解决这个问题。
最佳答案
如果您还没有解决这个问题,请确保您没有禁用相关应用程序的通知;这也会禁用 toast 。
关于android - Toast 消息未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27601611/