我需要一些帮助来放置onPause
我的代码。这是我onPause
今天早些时候建议的方法
@Override public void onPause() {
if (alertDialog != null && alertDialog.isShowing()) {
alertDialog.dismiss(); super.onPause(); } }
我的活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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.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 alertDialog = alertDialogBuilder.create();
alertDialog.show();
final EditText editText = (EditText) findViewById(R.id.typo1);
Button check = (Button) findViewById(R.id.check1);
check.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (editText.getText().toString().length()==0) {
Toast.makeText(getApplicationContext(),"Congrats!",Toast.LENGTH_LONG).show();
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
}
当我尝试将其放在onPause
下面时,alertDialog.show();
我得到一个语法错误void
,上面写着“令牌“void”上的语法错误,@预期”,当我尝试将其放在底部时,onStop
它无法识别alertDialog
我不知道如何解决这个问题问题,我已经解决了几个小时并且知道如何解决它。所以可以帮助我onPause
在我的活动中放置适当的位置
日志猫
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)