Note that there are some explanatory texts on larger screens.

plurals
  1. POApplication crashes after screen orientation changed
    text
    copied!<p>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.</p> <p>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:</p> <pre><code>Thread [&lt;1&gt; 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] </code></pre> <p>I plan to handle screen rotation later, but until then, I wish the default behavior to work correctly.</p> <p>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:</p> <pre><code>public class ProCalcApplication extends Application { private Engine engine; public ProCalcApplication() { super(); engine = new Engine(); } public Engine getEngine() { return engine; } } </code></pre> <p>How to solve this problem?</p> <hr> <p>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 ;)</p> <hr> <p>I've found the cause, yet no solution. The faulty XML code follows:</p> <p> </p> <pre><code>&lt;LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt; &lt;android.gesture.GestureOverlayView android:id="@+id/gestureOverlay" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3"&gt; &lt;ViewFlipper android:id="@+id/contextArea" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;/ViewFlipper&gt; &lt;/android.gesture.GestureOverlayView&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>Can someone maybe try to prove or disprove, that this code fails in described circumstances? Or point out, where did I make a mistake ;)</p> <p>My environment: HTC Desire Z (2.2.1), API 8 used. Eclipse version: Helios Service Release 2 Build id: 20110218-0911.</p> <p>Edit: Make it a little shorter:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"&gt; &lt;ViewFlipper android:id="@+id/contextArea" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="3"&gt; &lt;/ViewFlipper&gt; &lt;/LinearLayout&gt; </code></pre> <p>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).</p> <p>What did I miss?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload