Question on NotificationManager, setLatestEventInfo() and custom view.

by Jiri » Sat, 24 Oct 2009 00:07:38 GMT


Sponsored Links
 Hello,

I am creating a notification that displayes the progress of downloading 
files. Because I use a custom layout to be displyed in the expanded 
view. This custom view has a progressbar. I first make a call to the 
notification manager that will show the progress bar as being 
indeterminate and display a text "2 / 10" for instance.
Then when the downloading starts i only want to update the prgress bar.

<code>
     private void showNotification(String tickertxt, String displayTxt , 
  int total , int progress , Boolean indeterminate) {

         NotificationManager notifMgr = (NotificationManager) 
this.getSystemService(Service.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
new Intent(this, MainMenu.class), 0);

        // construct the Notification object.
        Notification notif = new Notification();

        notif.flags = Notification.FLAG_ONGOING_EVENT | 
Notification.FLAG_ONLY_ALERT_ONCE;
        notif.tickerText = tickertxt;
        notif.icon = R.drawable.icon;

        RemoteViews nmView = new RemoteViews( getPackageName(), 
R.layout.custom_notification_layout);
        nmView.setProgressBar(R.id.progressbar, total, progress, 
indeterminate);
        nmView.setTextViewText(R.id.TextView01, displayTxt);

        notif.contentView = nmView;

        notif.contentIntent = contentIntent;

         notifMgr.notify(R.layout.custom_notification_layout,  notif);
     }

</code>
So the first call i make when downloads are being prepared is:

showNotification("download..." , "n / n files" , 1 , 1 , false)

then when downloading starts:


showNotification("download..." , "n / n files" , class.getCurrent() , 
class.getTotal() , true)


What is bothering me is that I call the second call quit a lot and thus 
in the showNotification() a lot of objects are instantiated. In the docs 
it talks about  setLatestEventInfo() but this (afaik) cannot be applied 
when using a custom view.
Is this the way it is or is there a better technique.

Jiri



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Tmobile Native IM versi 1.1.2 worked via gprs/3G and wifi

iye...tapi sepertinya karena jaringannya deh

-- 
"Indonesian Android Community [id-android]" 

2. Tmobile Native IM versi 1.1.2 worked via gprs/3G and wifi

Mau nanya buat teman2 yg udah nyoba nih. Apakah ada delay waktu terima 
message dari lawan chat?
Di versi2 sebelumnya, saya selalu masukkan 2 file (IM dan 
IMprovider.apk), dan saya coba chat dari PC dgn Yahoo ID yang lain, kok 
kadang delay-nya sampai beberapa menit, bahkan perlu di-"pancing" dengan 
kita kirim outoing message dari IM, barulah incoming message-nya masuk 
semua.
Di versi 1.1.2 ini, saya coba masukkan 1 file saja (IM.apk saja), dan 
sepertinya masalah ini masih terjadi juga.

Ada yang mengalami kasus yang sama?

Thanks

Dom



IM terinstal dg baik dan working on my Spica.... (file attached, tinggal download dan copy ke SDCARD) ini tutorialnya : 1. download file IM-1.1.2.apk dan copy ke SDCARD 2. masuk ke adb ketik : su remount rw cp /sdcard/IM-1.1.2.apk /system/app remount ro
-- "Indonesian Android Community [id-android]"

3. Class Name

4. How to set onClickListener for elements in a Vector

5. OtterBox Commuter for MotoDroid atau Mileston

6. Misplaced Layout after 鈥渉ome 鈥?button and/or powersave screen

7. MPEG-4 vendor plugin data buffers