2011-11-02 44 views
16

Estoy tratando de usar notificaciones personalizadas en mi aplicación Android usando la muestra de Google de here (sección Creating a Custom Notification Layout). Como estoy usando este código exacto recibí un RuntimeException cada pocas veces que se lanza una notificación.Notificación personalizada: java.lang.RuntimeException: malas longitudes de matriz

Mi Seguimiento de la pila:

FATAL EXCEPTION: main 
java.lang.RuntimeException: bad array lengths 
    at android.os.Parcel.readIntArray(Parcel.java:677) 
    at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:369) 
    at android.app.NotificationManager.notify(NotificationManager.java:110) 
    at android.app.NotificationManager.notify(NotificationManager.java:90) 
    at com.****.service.UpdateFeedService.notifyUpdateProgress(UpdateFeedService.java:266) 
    at com.****.service.task.PodcastUpdaterTask.onProgressUpdate(PodcastUpdaterTask.java:63) 
    at com.****.service.task.PodcastUpdaterTask.onProgressUpdate(PodcastUpdaterTask.java:1) 
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:432) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:144) 
    at android.app.ActivityThread.main(ActivityThread.java:4937) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:521) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
    at dalvik.system.NativeStart.main(Native Method) 

Mi código:

private final Intent updateInProgressIntent = new Intent(this.context, PodcastListActivity.class); 
private RemoteViews updateInProgressContentView = null; 
private PendingIntent updateInProgressPendingIntent = null; 
private Notification updateInProgressNotification = null; 
... 
    @Override 
    public void onCreate() { 
     super.onCreate();  
... 
     this.updateInProgressPendingIntent = PendingIntent.getActivity(this, UPDATE_INPROGRESS_NOTIFICATION_ID, 
     this.updateInProgressIntent, PendingIntent.FLAG_UPDATE_CURRENT);  
     this.updateInProgressContentView = new RemoteViews(getPackageName(), R.layout.custom_notification); 
... 
    } 

    public void notifyUpdateProgress(final int index, final int size, final Podcast podcast) { 

     this.updateInProgressContentView.setImageViewBitmap(
       R.id.image, ActivityHelper.getBitmap(context, podcast.getThumbnailAsset())); 
     this.updateInProgressContentView.setTextViewText(R.id.title, "some msg"); 
     this.updateInProgressContentView.setTextViewText(R.id.text, podcast.getName()); 
     this.updateInProgressNotification.contentView = this.updateInProgressContentView;  
     this.updateInProgressNotification.contentIntent = this.updateInProgressPendingIntent;    
     this.notificationManager.notify(UPDATE_INPROGRESS_NOTIFICATION_ID, this.updateInProgressNotification); 

     ... 
     }  

Si se sustituye la notificación personalizada con una normal (con setLatestEventInfo()) no tengo problemas.

Respuesta

5

Ok, entonces finalmente encuentro la solución. ¡No puede volver a utilizar el mismo objeto RemoteView como yo! Estaba creando RemoteView en el método onCreate(), luego estaba configurando sus atributos en notifyUpdateProgress(). Si creo el objeto en notifyUpdateProgress() justo antes de usarlo, ya no tengo excepciones.

+1

A veces me sale esta falla incluso con una nueva RemoteView, por lo que creo que está relacionada con los mapas de bits como lo menciona @Brigham – tokudu

+0

@ La respuesta de Brigham es correcta. Es posible que haya estado filtrando objetos 'Bitmap' alrededor de su' RemoteView'. –

18

Si ve este problema, investigue el tamaño del mapa de bits que está utilizando para la imagen de notificación.

Si es demasiado grande, puede ver este error, así como un OutOfMemoryError en el lado del sistema Android.

+0

m No uso ninguna imagen aparte del icono de la aplicación que también se configuró en el diseño – DjHacktorReborn

Cuestiones relacionadas