android.app.SuperNotCalledException: Activity未调用super.onStop()方法

18

我正在使用几个传感器 - MediaRecorder 和 MediaPlayer、NotificationManager、WakeLock 和 LocationListener...

这是我的 onResume() 和 onPause() 函数:

void onResume() {
  super.onResume();

  //GPS Sensor
  locationListener = new MyLocationListener();
  locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  locationManager.requestLocationUpdates(
      LocationManager.GPS_PROVIDER, 0, 0, locationListener);

  // Notification Manager
  gNotificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  gNotification = new Notification();
  gNotification.vibrate = gVibrate;

}

...

void onPause() {
  super.onPause();

  // Release the Recorder
  if (mRecorder != null) {
    mRecorder.release();
    mRecorder = null;
  }

  // Release the Media Player
  if(mPlayer != null) {
    mPlayer.release();
    mPlayer = null; 
  }

  // Release Power Manager
  wake.Stop();
  wake = null;

  // Release Location Listener
  locationManager.removeUpdates(locationListener); 
  locationManager = null;

}

以下是Logcat输出...

threadid=1: thread exiting with uncaught exception
(group=0x40015560) 
FATAL EXCEPTION: main
android.app.SuperNotCalledException: Activity
{changethispackage.beforesubmitting.tothemarket.sonicdrift/
changethispackage.beforesubmitting.tothemarket.sonicdrift.SonicDrift}
did not call through to super.onStop()

at android.app.Activity.performStop(Activity.java:3875)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2690)
at android.app.ActivityThread.access$2100(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:964)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native
Method) W/InputManagerService(   96): Window already focused, ignoring
focus gain of:
com.android.internal.view.IInputMethodClient$Stub$Proxy@40713650
I/Process (17118): Sending signal. PID: 17118 SIG: 9
I/ActivityManager(   96): Process
changethispackage.beforesubmitting.tothemarket.sonicdrift (pid 17118)
has died. I/WindowManager(   96): WIN DEATH: Window{40958d98
changethispackage.beforesubmitting.tothemarket.sonicdrift/changethispackage.
beforesubmitting.tothemarket.sonicdrift.SonicDrift
paused=false} I/WindowManager(   96): WIN DEATH: Window{40991f90
SurfaceView paused=false}

我该怎么修复这个错误?我尝试在onPause()中添加super.onStop()


请查看此链接,可能会对您有所帮助:http://stackoverflow.com/questions/3124965/android-unable-to-stop-activity - kosa
是的,在我发布之前,那是我发现的其中一个...我猜因为我没有onStop()函数,所以我不确定我是否需要它...也尝试将super.onStop()添加到我的onPause()函数中,但是出现了相同的错误... - jesses.co.tt
不可以,你需要有onStop函数。你不能从暂停调用super.onStop()。暂停和停止是不同的操作。 - kosa
我知道它们是不同的,以及一般的生命周期...但我以前从未在Processing/Android中使用过onStop...我会再试一次(以前试过,但我记不起当时给我的错误了..) - jesses.co.tt
如果我尝试添加一个onStop()函数,控制台会显示:“onStop() 在 changethispackage.beforesubmitting.tothemarket.sonicdrift.SonicDrift 中已定义”。 - jesses.co.tt
显示剩余2条评论
2个回答

44

您需要确保在覆盖的方法中使用 super.onStopsuper.onDestroy。这可能是您遇到问题的原因:

@Override
protected void onStop() {
    Log.w(TAG, "App stopped");

    super.onStop();
}

@Override
protected void onDestroy() {
    Log.w(TAG, "App destroyed");

    super.onDestroy();
}

1
很抱歉这么晚才接受这个答案... Processing 以前的工作方式实际上并不支持这些方法(它是一个有趣的 Android 高级库),所以我对它们的实现感到困惑... 不过现在一切都解决了。 - jesses.co.tt

0

在添加了空的onPause和onResume事件之后,停止抛出异常(我仍然添加了您的方法,以确保安全)。

尽管如此,第二个活动仍然似乎没有任何原因而停止。但我会另外提一个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接