Question on NotificationManager, setLatestEventInfo() and custom view.

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

Sponsored Links

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.

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

         NotificationManager notifMgr = (NotificationManager) 

        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 | 
        notif.tickerText = tickertxt;
        notif.icon = R.drawable.icon;

        RemoteViews nmView = new RemoteViews( getPackageName(), 
        nmView.setProgressBar(, total, progress, 
        nmView.setTextViewText(, displayTxt);

        notif.contentView = nmView;

        notif.contentIntent = contentIntent;

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

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.



Other Threads

1. Eclipse hangs when launching program file.. AGAIN !

Anyone found a fix for this yet?

2. Problem using XMPP demo in latest SDK emulator m5 rc 14

Thank you very much!I used to think that the service on my emulator
was broken


3. NullPointerException Error (Very Easy)

4. MapView inside ScrollView doesn't move right

5. is there any plans to release c++ version of andriod

6. Progmatic Selection of List Item

7. Any one tried uisng mediaplayer example ,I ma unable to play video file from local directory