Why does keyboard-slide crash my app?

前端 未结 4 1400
春和景丽
春和景丽 2020-12-15 11:14

If I physically slide out the keyboard on my Moto Droid A855, it crashes my test app with the stack trace pasted below. I don\'t understand why?

Also, if I start my

相关标签:
4条回答
  • 2020-12-15 11:53

    yeah I don't see this bug before.. but then again I have this in my manifest

     <activity
            android:name=".MainActivity"
            android:configChanges="keyboardHidden|navigation"
            android:label="@string/app_name"
            android:launchMode="singleTop" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
    
    </activity>
    
    0 讨论(0)
  • 2020-12-15 11:57

    I know this question was asked almost two years ago, but since then a very easy fix has been implemented. Just add android:configChanges="orientation|keyboard|keyboardHidden" into each Activity call in the Manifest.

    0 讨论(0)
  • 2020-12-15 12:01

    It's really difficult to help you if you don't provide some part of your code... anyway, this error is not new and there are some workarounds in order to solve it (I guess is some bug)... try to do this:

    @Override
    protected void onDetachedFromWindow() {
        try {
            super.onDetachedFromWindow();
        }
        catch (IllegalArgumentException e) {
            stopFlipping();
        }
    }
    

    This is for overriding the onDetachedFromWindow and I hope it works for you.

    0 讨论(0)
  • 2020-12-15 12:15

    To resolve this issue you must

    • Define a new class called MyViewFlipper which overrides ViewFlipper (see below)
    • Reference that new class anywhere you would have previously referenced ViewFlipper
    • Define your class and layout as shown below:

    New class called MyViewFlipper. Contains the following:

    package com.gtosoft.dash; // change this to match your own app. 
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.widget.ViewFlipper;
    
    public class MyViewFlipper extends ViewFlipper {
    
        public MyViewFlipper(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        protected void onDetachedFromWindow() {
            try{
                super.onDetachedFromWindow();
            }catch(Exception e) {
                Log.d("MyViewFlipper","Stopped a viewflipper crash");
                stopFlipping();
            }
        }
    }
    

    Now to use this "fixed" version of ViewFlipper you have to reference it in the xml layout. Since it is basically a "custom view", you have to fully qualify the package path to MyViewFlipper, as seen here:

    <com.gtosoft.dash.MyViewFlipper
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/vFlipper"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        (insert all the other old layout code here)
    
    </com.gtosoft.dash.MyViewFlipper>
    

    Now the app no longer crashes on the keyboard slide event or if the app is started with slide already out. Look for this in the log:

    06-11 20:08:15.811 D/MyViewFlipper( 6106): Stopped a viewflipper crash
    

    Credit: http://code.google.com/p/android/issues/detail?id=6191

    0 讨论(0)
提交回复
热议问题