android - Toast 消息未显示

标签 android android-ui toast android-toast

我正在尝试使用以下代码在我的应用程序中显示 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 。

https://code.google.com/p/android/issues/detail?id=35013

关于android - Toast 消息未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27601611/

相关文章:

android - 强制关闭启动 Intent ,android list 中提到了该 Activity

android - 如何从 Toast 对象中获取文本

android - 点击事件只显示一个Toast?

vb.net - 为什么我的文字一直突出显示?

java - 使用谷歌地图 V2 在多段线中绘制箭头

android - 将旧的 gradle 项目导入新的 android studio 版本

android - 如何在 Flutter 中创建可扩展的 ListView

android - 如何选择性地装饰 RecyclerView 项目

java - 如何为自定义可扩展 ListView 子项设置选择器

android - 键盘在使用adjustPan时隐藏操作栏