I've got the following problem. After starting, application works fine - even after changing the screen orientation. The application is not yet prepared to handle orientation change (eg. alternative layout and so on), so just the rotated default layout appears and it's OK. However, when I leave the application by pressing the back key, change the orientation and immediately after start the application again, it crashes. After a crash, if I start application once again, it works well until the previously described circumstances occur - then it crashes.
I've connected the device to computer and run the application in debug mode. After restarting, an exception is thrown even before calling onCreate. The crash callstack follows:
Thread [<1> main] (Suspended (exception IllegalArgumentException))
WindowManagerImpl.removeViewImmediate(View) line: 262
Window$LocalWindowManager.removeViewImmediate(View) line: 436
ActivityThread.handleDestroyActivity(IBinder, boolean, int, boolean) line: 4022
ActivityThread.handleRelaunchActivity(ActivityThread$ActivityRecord, int) line: 4127
ActivityThread.access$2400(ActivityThread, ActivityThread$ActivityRecord, int) line: 136
ActivityThread$H.handleMessage(Message) line: 2183
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 143
ActivityThread.main(String[]) line: 5068
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 858
ZygoteInit.main(String[]) line: 616
NativeStart.main(String[]) line: not available [native method]
I plan to handle screen rotation later, but until then, I wish the default behavior to work correctly.
I've overriden only the onCreate Activity's method. I've also got custom application class, which creates an instance of application-wide used engine class:
public class ProCalcApplication extends Application
{
private Engine engine;
public ProCalcApplication()
{
super();
engine = new Engine();
}
public Engine getEngine()
{
return engine;
}
}
How to solve this problem?
I've done some more testing. I've commented out whole code, leaving only the default implementation of onCreate method (super() + setContentLayout()). The problem persisted, so I've commented out whole layout XML and the application finally stopped crashing. I'm in process of nailing down the faulty entry, please stand by ;)
I've found the cause, yet no solution. The faulty XML code follows:
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<android.gesture.GestureOverlayView android:id="@+id/gestureOverlay" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3">
<ViewFlipper android:id="@+id/contextArea" android:layout_width="match_parent" android:layout_height="match_parent">
</ViewFlipper>
</android.gesture.GestureOverlayView>
</LinearLayout>
Can someone maybe try to prove or disprove, that this code fails in described circumstances? Or point out, where did I make a mistake ;)
My environment: HTC Desire Z (2.2.1), API 8 used. Eclipse version: Helios Service Release 2 Build id: 20110218-0911.
Edit: Make it a little shorter:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<ViewFlipper android:id="@+id/contextArea" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3">
</ViewFlipper>
</LinearLayout>
And a little more info; API 8 in emulator: two screen orientation changes (Ctrl+F12) and application crashes. API 10 in emulator: two screen orientation changes and the screen remains in landscape mode regardless of orientation (application does not crash, though).
What did I miss?