I have the following problem. After starting the application works fine - even after changing the screen orientation. The application is not yet prepared for handling orientation changes (for example, an alternative layout, etc.), therefore, only the expanded layout by default appears, and everything is in order. However, when I leave the application by pressing the back key, change the orientation and immediately after starting the application it will work again. After a crash, if I run the application again, it works well until the previously described circumstances are detected - then it will work.
I connected the device to the computer and ran the application in debug mode. After a restart, an exception is thrown even before the onCreate function is called. Collision Column:
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 the screen rotation later, but until then, I want the default behavior to work correctly.
I exceeded only the onCreate Activity method. I also have my own application class that creates an instance of the used machine class for the entire application:
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 did some more tests. I commented all the code, leaving only the onCreate (super () + setContentLayout ()) method by default. The problem continued, so I commented on the whole XML format and the application finally stopped. I'm in the process of nailing an erroneous record, please wait :)
I found a reason, but no solution. The following is the wrong XML code:
<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 try to prove or disprove that this code does not work under the circumstances described? Or indicate where I made a mistake;)
My environment: HTC Desire Z (2.2.1), used by API 8. 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 information; API 8 in the emulator: two screen orientation changes (Ctrl + F12) and application crashes. API 10 in the emulator: two changes in screen orientation, and the screen remains in landscape mode regardless of orientation (the application does not crash, though).
What did I miss?