2010-06-11 9 views
9

Si je fais glisser physiquement le clavier sur mon Moto Droid A855, il bloque mon application de test avec la trace de pile collée ci-dessous. Je ne comprends pas pourquoi?Pourquoi le clavier-slide plante-t-il mon application?

En outre, si je démarre mon application avec le clavier, mon application se bloque immédiatement au démarrage.

L'application consiste en une activité qui contient un viewflipper en tant que présentation de la vue principale. Le viewflipper contient deux linearlayouts ...

trace de la pile:

06-10 21:10:17.652 E/AndroidRuntime(3785): Uncaught handler: thread main exiting due to uncaught exception 
06-10 21:10:17.668 E/AndroidRuntime(3785): java.lang.IllegalArgumentException: Receiver not registered: [email protected] 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:667) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.app.ApplicationContext.unregisterReceiver(ApplicationContext.java:747) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:321) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.widget.ViewFlipper.onDetachedFromWindow(ViewFlipper.java:104) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.View.dispatchDetachedFromWindow(View.java:5835) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1076) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1074) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.ViewRoot.dispatchDetachedFromWindow(ViewRoot.java:1570) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.ViewRoot.doDie(ViewRoot.java:2556) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.ViewRoot.die(ViewRoot.java:2526) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:218) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.view.Window$LocalWindowManager.removeViewImmediate(Window.java:436) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3498) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3599) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.app.ActivityThread.access$2300(ActivityThread.java:119) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1867) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.os.Handler.dispatchMessage(Handler.java:99) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.os.Looper.loop(Looper.java:123) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at java.lang.reflect.Method.invokeNative(Native Method) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at java.lang.reflect.Method.invoke(Method.java:521) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
06-10 21:10:17.668 E/AndroidRuntime(3785):  at dalvik.system.NativeStart.main(Native Method) 
06-10 21:10:17.684 I/Process (1017): Sending signal. PID: 3785 SIG: 3 

EDIT: mise en page XML ajoutée et des extraits pertinents de l'activité principale.

fichier de mise en page XML Tout

<?xml version="1.0" encoding="utf-8"?> 


<ViewFlipper 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/vFlipper" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

       <!-- Linear Layout 1: messages and overview. --> 
       <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        > 

       <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent" android:layout_height="wrap_content"> 
       <TextView 
         android:text="Connection info" 
         android:id="@+id/tvCon1" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:background="#F0F0F0" 
         android:textColor="#FF0000" 
         /> 
       </TableRow> 


       <ScrollView 
         android:id="@+id/ScrollView01" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent"> 

           <TextView 
             android:id="@+id/tvMessages" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            android:text="" 
            /> 

       </ScrollView> 

     </LinearLayout> 


     <!-- Linear Layout 2: settings --> 
     <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        > 


       <TableRow 
         android:id="@+id/TableRow03" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content"> 

           <TextView 
           android:text="hello world" 
           android:id="@+id/asdfasdf2" 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content" 
           /> 
       </TableRow>     

     </LinearLayout> 

</ViewFlipper> 

extraits de code de l'activité principale:

/** 
* Attempt (not currently working) to work around this bug: http://code.google.com/p/android/issues/detail?id=6191 
* TODO: make it work. 
*/ 
@Override 
public void onDetachedFromWindow() { 
     Log.d("Dash","OnDetachedFromWindow()"); 

     try { 
     super.onDetachedFromWindow(); 
    } 
    catch (Exception e) { 
     ViewFlipper v = (ViewFlipper)findViewById(R.id.vFlipper); 
     if (v != null) { 
       Log.d("Dash","De-Bug hit. e=" + e.getMessage()); 
       v.stopFlipping(); 
     } 
    } 
} 

Répondre

21

Pour résoudre ce problème, vous devez

  • Définir une nouvelle classe appelée MyViewFlipper qui remplace ViewFlipper (voir ci-dessous)
  • référence que la nouvelle classe que vous ne importe où ont déjà référencé ViewFlipper
  • Définir votre classe et disposition comme indiqué ci-dessous:

Nouvelle classe appelée MyViewFlipper. Contient les éléments suivants:

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(); 
     } 
    } 
} 

maintenant à utiliser cette version « fixe » de ViewFlipper vous devez faire référence dans la mise en page XML. Comme il est fondamentalement une « vue personnalisée », vous devez qualifier complètement le chemin du paquet à MyViewFlipper, comme on le voit ici:

<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> 

Maintenant, l'application ne se bloque plus sur l'événement clavier slide ou si l'application est démarré avec glisse déjà. Recherchez ce dans le journal:

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

Crédit: http://code.google.com/p/android/issues/detail?id=6191

+0

Je pense que j'ai fait une petite faute de frappe - le

+0

Il vous manque une ligne importante: appelez stopFlipping() dans le bloc catch pour qu'il appelle updateRunning(). –

5

Il est vraiment difficile de vous aider si vous ne fournissez pas une partie de votre code ... De toute façon, cette erreur n'est pas nouvelle et il y a quelques solutions pour la résoudre (je suppose que c'est un bug) ... essayez de faire ceci:

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

Ceci est pour remplacer le onDetachedFromWindow et j'espère que cela fonctionne pour vous.

+0

Si vous avez besoin de code, demandez-le. –

+0

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

+0

J'ai essayé d'implémenter cette correction hier soir mais cela n'avait aucun effet. Tout d'abord, Eclipse n'a pas aimé "protégé" donc je devais le rendre public. De plus, stopFlipping devait être qualifié en utilisant findviewById, etc. Et j'ai mis des messages de débogage dans le nouveau bloc de code et j'ai constaté qu'il ne tirait même pas, jamais. –

2

Je sais que cette question a été posée il y a près de deux ans, mais depuis lors, a été mis en œuvre une solution très facile. Ajoutez simplement android:configChanges="orientation|keyboard|keyboardHidden" dans chaque appel d'activité du manifeste.

0

ouais je ne vois pas ce bug avant ..mais là encore je l'ai dans mon manifeste

<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> 
Questions connexes