18

Im using a few sensors - MediaRecorder and MediaPlayer, NotificationManager, a WakeLock, and LocationListener...

Here is my onResume() and onPause() functions:

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;

}

And here's the Logcat output...

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}

How do I fix this error? I've tried to add super.onStop() to my onPause().

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
jesses.co.tt
  • 2,689
  • 1
  • 30
  • 49
  • Check this it may help you http://stackoverflow.com/questions/3124965/android-unable-to-stop-activity – kosa Feb 22 '12 at 14:51
  • Yeah, that was one of the ones I found before I posted... I guess b/c I dont have a onStop() function, I wasnt sure that I needed it... also tried to add super.onStop() to my onPause() function, but same error... – jesses.co.tt Feb 22 '12 at 14:55
  • No, you need to have onStop function. You can't call super.onStop() from pause. Pause/Stop are different operations. – kosa Feb 22 '12 at 14:58
  • I understand that they're different, and the general lifecycle... but Ive never used onStop in Processing/Android before.. Ill give it another try (did before, but cant remember the error it gave me then..) – jesses.co.tt Feb 22 '12 at 15:00
  • If I try to add a onStop() function, the console says: "onStop() is already defined in changethispackage.beforesubmitting.tothemarket.sonicdrift.SonicDrift" – jesses.co.tt Feb 22 '12 at 15:08
  • FYI, these answers were not helpful, but the error seems to not be showing on Android 4.0 anymore... maybe there's some internal OS try/catch ... ?? – jesses.co.tt Aug 18 '12 at 20:27
  • https://youtu.be/wYlEzYWtesM – Chandra Sekhar Nov 05 '18 at 03:17

2 Answers2

44

You need to make sure that you have super.onStop and super.onDestroy in your overridden methods. This could be a good candidate for the problem you have:

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

    super.onStop();
}

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

    super.onDestroy();
}
edwoollard
  • 12,245
  • 6
  • 43
  • 74
Future2020
  • 9,939
  • 1
  • 37
  • 51
  • 1
    Sorry for taking so long to accept this answer... the way that Processing used to work, it didn't actually support these methods out of the box (its a funny higher level library for Android), so I was confused about their implementation... all sorted now though. – jesses.co.tt Jul 30 '13 at 18:26
0

Stopped throwing exeptions after adding empty onPause and onResume events(I've added your methods anyways, just to be safe).

Altough, the second activity still halts for seemingly no reason. But I'll make an another question about that.

Frontrider
  • 47
  • 1
  • 10