Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:34:15+00:00 2026-05-22T02:34:15+00:00

I’ve got the following problem. After starting, application works fine – even after changing

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:34:15+00:00Added an answer on May 22, 2026 at 2:34 am

    I’ve found out, what did I missed 🙂 Since no one answered, I’ll leave an answer for everyone, who’ll encounter the same problem.

    It turns out, that the problem described is a generally known Android libraries bug: ViewFlipper fails to handle screen orientation change properly. It have appeared in API 2.1 and continues until 3.0, where it is believed to be fixed. Unfortunatelly, most of today’s smartphones suffer from this problem, as usually they have 2.2 or 2.3 onboard.

    The solution is either to handle screen orientation change manually (see Activity restart on rotation Android ) or implement the view changes and animations manually, using FrameLayout, view visibility and animation classes.

    Another one is to use Eric Burke’s SafeViewFlipper class:

    /**
     * Works around Android Bug 6191 by catching IllegalArgumentException after
     * detached from the window.
     *
     * @author Eric Burke (eric@squareup.com)
     */
    public class SafeViewFlipper extends ViewFlipper {
      public SafeViewFlipper(Context context) {
        super(context);
      }
    
      public SafeViewFlipper(Context context, AttributeSet attrs) {
        super(context, attrs);
      }
    
      /**
       * Workaround for Android Bug 6191:
       * http://code.google.com/p/android/issues/detail?id=6191
       * <p/>
       * ViewFlipper occasionally throws an IllegalArgumentException after
       * screen rotations.
       */
      @Override protected void onDetachedFromWindow() {
        try {
          super.onDetachedFromWindow();
        } catch (IllegalArgumentException e) {
          Log.d(TAG, "SafeViewFlipper ignoring IllegalArgumentException");
    
          // Call stopFlipping() in order to kick off updateRunning()
          stopFlipping();
        }
      }
    }
    

    You can use it while creating the layout from the code as well as embed it into your xml layout file (you’ll have to qualify it fully, eg. <com.myapp.SafeViewFlipper />).

    See also http://code.google.com/p/android/issues/detail?id=6191 for more informations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.