onResume() not called second time an Activity is launched

android

Solution

I found the problem, and it's a bit esoteric.

I have a large static data structure which is loaded in a class static initialiser. There was a bug in that initialiser causing an infinite loop the second time it was called if the data structure was still loaded.

Because that class is referenced in my Activity, the class loader is loading it before `onCreate()` or `onResume()` is called.

The loop gave the appearance that the Activity loader had hung.

Problem

During the normal course of development, I noticed that a particular activity appears to have stopped responding the second time it is called. i.e. `menu->(intent)->activity->(back button)->menu->(intent)` There is nothing relevant in logcat. I don't even know where to start debugging this nor what code to show so here are the `onClick` and `onResume` fragments: ``` if (!dictionary.getClassName().equals("")) { this.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent i; i = new Intent(mContext, NVGlobeNavigatorVC.class); i.putExtra("PAGE_TITLE", title); i.putExtra("TITLE", _dictionary._title); mContext.startActivity(i); }); } else { findViewById(R.id.greaterthan).setVisibility(View.GONE); } ``` and in the Activity being launched: ``` @Override protected void onResume() { super.onResume(); ... ``` Nothing unusual in manifest either: ``` <activity android:name=".NVViews.NVGlobeNavigatorVC" android:theme="@style/WindowTitleBackground" android:label="GlobeNavigator"/> ``` For clarity, I put breakpoints on `mContext.startActivity(i)` and `super.onResume()`. I click the view with the `onClickListener` and both breakpoints are hit as expected. I then press the back button which returns me to the menu. `onPause()` is called as expected. I touch the view to launch the activity again, and the breakpoint on `startActivity` is hit but not in `onResume()` in the target activity. The screen goes black and the only way I can get going again is to restart the app. If I pause the debugger, it pauses in `dalvik.system.NativeStart()` which implies that the activity is never relaunched. I don't think it's relevant, but I'm using Intellij IDEA and have deleted all of the output directories, invalidated the caches and done a full rebuild. Target API is 8. I've tested on 2.3 and 4.0.4. Any ideas? I'm stumped. [EDIT] In `onPause`, I save some stuff to prefs. The purpose of `onResume()` is to get them back again: ``` @Override protected void onPause() { super.onPause(); SCPrefs.setGlobeViewViewPoint(globeView.getViewPoint()); SCPrefs.setGlobeViewZoom(globeView.getZoom()); SCPrefs.setGlobeViewScale(globeView.getScale()); } ```

Original source