17

hereの Google のサンプルを使用して、Android アプリケーションでカスタム通知を使用しようとしています(セクションカスタム通知レイアウトの作成)。この正確なコードを使用しているためRuntimeException、数回ごとに通知が発生します。

私のスタックトレース:

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)

私のコード:

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

        ...
        }       

カスタム通知を標準の通知 ( ) に置き換えればsetLatestEventInfo()、問題はありません。

4

2 に答える 2

23

この問題が発生している場合は、通知画像に使用しているビットマップのサイズを調べてください。

OutOfMemoryError大きすぎる場合は、Androidシステム側と同様にこのエラーが表示される場合があります。

于 2012-05-14T22:45:44.707 に答える
7

わかりましたので、最終的に解決策を見つけます。

RemoteView私のように同じオブジェクトを再利用することはできません。

メソッドでを作成してRemoteViewから、 でonCreate()その属性を設定していましたnotifyUpdateProgress()

オブジェクトをnotifyUpdateProgress()使用する直前に作成すると、もう例外はありません。

于 2011-11-04T21:34:57.893 に答える