2011-11-02 12 views
16

मैं here (अनुभाग Creating a Custom Notification Layout) से Google के नमूने का उपयोग करके अपने एंड्रॉइड एप्लिकेशन में कस्टम नोटिफिकेशन का उपयोग करने का प्रयास कर रहा हूं। चूंकि मैं इस सटीक कोड का उपयोग कर रहा हूं, इसलिए मुझे RuntimeException प्रत्येक अधिसूचना को निकाल दिया गया है।कस्टम अधिसूचना: java.lang.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() के साथ) के साथ कस्टम अधिसूचना की जगह मैं कोई समस्या नहीं।

उत्तर

5

ठीक है, इसलिए मुझे अंत में समाधान मिल गया। आप उसी रिमोट व्यू ऑब्जेक्ट का पुन: उपयोग नहीं कर सकते जैसे मैंने किया था! मैं ऑनक्रेट() विधि में रिमोट व्यू बना रहा था, तो मैं अधिसूचना प्रगति() को सूचित करने में अपनी विशेषताओं को सेट कर रहा था। यदि मैं इसे उपयोग करने से पहले अद्यतनडेटा प्रोग्रेस() को सूचित करने में ऑब्जेक्ट बनाता हूं, तो मुझे अब अपवाद नहीं है।

+1

कभी-कभी मुझे यह ब्रांड एक नया नया रिमोट व्यू के साथ भी मिलता है, इसलिए मुझे लगता है कि यह @ बिघेम – tokudu

+0

@ ब्रिघम का उत्तर सही है, जैसा कि बिटमैप्स से संबंधित है। हो सकता है कि आप अपने 'रिमोट व्यू' के आस-पास 'बिटमैप' ऑब्जेक्ट्स लीक कर रहे हों। –

18

यदि आप इस समस्या को देख रहे हैं, तो बिटमैप के आकार की जांच करें जिसका आप अधिसूचना छवि के लिए उपयोग कर रहे हैं।

यदि यह बहुत बड़ा है तो आप एंड्रॉइड सिस्टम पक्ष पर OutOfMemoryError पर यह त्रुटि देख सकते हैं।

+0

एम ऐप आइकन के अलावा किसी भी छवि का उपयोग नहीं कर रहा है जो लेआउट में भी सेट है – DjHacktorReborn

संबंधित मुद्दे