下面是我用来向用户显示信息的 alertDialog。
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.show();
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setTitle("Title");
alertDialog.setMessage("dialog");
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
现在,我一直在研究并在 stackoverflow 上四处寻找,看看如何让这个对话框显示一次,我发现了一些可以提供帮助的东西。我已经研究了这段代码,并将其分解到我在这方面的知识范围内,但我似乎无法弄清楚问题所在。
final SharedPreferences settings = getSharedPreferences("pref_name", 0);
boolean disappear = settings.getBoolean("installed", false);
if (disappear == false) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
AlertDialog alert = alertDialog .create();
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setTitle("Title");
alertDialog.setMessage("dialog");
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
settings.edit().putBoolean("installed", true).commit();
}
alertDialog.show();
问题是,当我在模拟器上启动此应用程序时,我的对话框没有显示,并且我的应用程序中没有任何响应,与此链接中的这个人问题非常相似,我发现警报对话框的共享首选项使我的应用程序无响应我必须尝试分解此代码并尝试弄清楚为什么会发生这种情况,但我在这方面的知识有限。所以有人可以帮助解决这个问题。
10-13 03:10:37.496: E/AndroidRuntime(761): FATAL EXCEPTION: main
10-13 03:10:37.496: E/AndroidRuntime(761): android.app.SuperNotCalledException: Activity {com.theproblemsolver/com.theproblemsolver.MainActivity} did not call through to super.onPause()
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.Activity.performPause(Activity.java:5210)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1226)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3002)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2971)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2949)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.ActivityThread.access$800(ActivityThread.java:141)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1245)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.os.Looper.loop(Looper.java:137)
10-13 03:10:37.496: E/AndroidRuntime(761): at android.app.ActivityThread.main(ActivityThread.java:5041)
10-13 03:10:37.496: E/AndroidRuntime(761): at java.lang.reflect.Method.invokeNative(Native Method)
10-13 03:10:37.496: E/AndroidRuntime(761): at java.lang.reflect.Method.invoke(Method.java:511)
10-13 03:10:37.496: E/AndroidRuntime(761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-13 03:10:37.496: E/AndroidRuntime(761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-13 03:10:37.496: E/AndroidRuntime(761): at dalvik.system.NativeStart.main(Native Method)