2

When I press the Home button, the app should be paused, save all state and work fine. Instead I get this error:

java.lang.RuntimeException: Unable to pause activity {be.test.tester/be.test.tester.DataScreen}: java.lang.IllegalStateException: Derived class did not call super.onSaveInstanceState() at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3641) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3598) at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3574) at android.app.ActivityThread.access$2500(ActivityThread.java:136) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2186) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:143) at android.app.ActivityThread.main(ActivityThread.java:5068) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.IllegalStateException: Derived class did not call super.onSaveInstanceState() at android.view.View.dispatchSaveInstanceState(View.java:6087) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1207) at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1207) at android.view.View.saveHierarchyState(View.java:6068) at com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1475) at android.app.Activity.onSaveInstanceState(Activity.java:1106) at android.app.Activity.performSaveInstanceState(Activity.java:1056) at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1289) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3623) ... 12 more

My activity reacts on touch:

public class DataScreen extends Activity implements OnGestureListener{   

I'm getting some extra's from the intent:

totUsage = Integer.parseInt(getIntent().getStringExtra("extraTotUsage"));
    limit = Integer.parseInt(getIntent().getStringExtra("extraLimit"));
    Bundle bundle = getIntent().getExtras();
    mylist = (ArrayList<HashMap<String, String>>) bundle.get("extraMyList");

A custom view is showing data (canvas). When you scroll on screen, data changes in custom view (set, get method) and redraws itself.

I don't really manage the onSaveInstanceState here, don't really know if I have to.

My app is onTop of the stack, because of:

i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

I don't understand the error.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user601302
  • 49
  • 1
  • 4
  • 7
  • 3
    The stacktrace suggests that you are not calling inherited version of `onSaveInstanceState`. If you have overriden this method (and I'm not sure if you did, your wording is a bit unclear about that), you must have `super.onSaveInstanceState` called there. – Xion Apr 20 '11 at 09:38
  • I'm not overriding them. Not in costum view and not in the activity. – user601302 Apr 20 '11 at 09:48

3 Answers3

5

You should override onSaveInstanceState and call its super method like shown below. At least it helped me with the same problem.

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    // your stuff or nothing
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    // your stuff or nothing
}
Christian
  • 7,062
  • 5
  • 36
  • 39
  • 4
    If this solves the problem (with "nothing"), it seems to be evidence of a bug in android code.. I'd hate to say it, but it makes me worry about other faulty guarantees.. – snapfractalpop May 16 '12 at 20:47
  • @snapfractalpop If you overload a method how else would it call the higher level code if you didn't then refer to the super method?! – melodiouscode Aug 20 '12 at 07:12
  • 1
    @jamesakadamingo I meant by "with 'Nothing'" that the methods are effectively not overridden. – snapfractalpop Aug 20 '12 at 16:00
  • @snapfractalpop: but it helps. Unfortunately, I share your concern above. – Christian Aug 20 '12 at 16:17
  • 1
    This mostly worked for me, but I also had to add try { ... } catch (IllegalStateException e) { } around both of the super calls to get it working correctly. Odd. – WOUNDEDStevenJones Oct 30 '12 at 22:01
2

I've just been dealing with this problem. In my app the main activity allows a second activity to be called to display info/instructions etc, it also has a surface view that draws the runtime element of the app.

The main activity has a variable to hold the surface view, if that variable hasn't been set before the info/instructions activity is called I get this error. I simply moved the surface view variable assignment into the main activity onCreate and all is well.

Kev
  • 21
  • 2
0

It is also possible that one uses a custom preference (e.g. custom dialog preference) that does not call "super.onSavedInstanceState()" which leads to the same error.

denis
  • 1,393
  • 3
  • 14
  • 34