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. Problem with looping through the buttons in the Layout

I'm using TableLayout for my application.
I do have 16 buttons (4 rows and 4 columns) inside the layout.

I'm able to assign the text to each button by assigning value to
R.id.Button01, 02, 03 .... Button16.

Take this as an example code.


                ((Button)findViewById(R.id.Button01)).setText(list.get
(0).toString());
                
((Button)findViewById(R.id.Button02)).setText(list.get(1).toString
());
                
((Button)findViewById(R.id.Button03)).setText(list.get(2).toString
());
                
((Button)findViewById(R.id.Button04)).setText(list.get(3).toString
());
                
((Button)findViewById(R.id.Button05)).setText(list.get(4).toString
());
                
((Button)findViewById(R.id.Button06)).setText(list.get(5).toString
());
                
((Button)findViewById(R.id.Button07)).setText(list.get(6).toString
());
                
((Button)findViewById(R.id.Button08)).setText(list.get(7).toString
());
                
((Button)findViewById(R.id.Button09)).setText(list.get(8).toString
());
                
((Button)findViewById(R.id.Button10)).setText(list.get(9).toString
());
                
((Button)findViewById(R.id.Button11)).setText(list.get(10).toString
());
                
((Button)findViewById(R.id.Button12)).setText(list.get(11).toString
());
                
((Button)findViewById(R.id.Button13)).setText(list.get(12).toString
());
                
((Button)findViewById(R.id.Button14)).setText(list.get(13).toString
());
                
((Button)findViewById(R.id.Button15)).setText(list.get(14).toString
());
                
((Button)findViewById(R.id.Button16)).setText(list.get(15).toString
());


But what I want is similar to following code.

      for(int i=0; i< 16; i++)
      {

           ((Button)findViewById(R.id.Button[i] )).setText(list.get
(i).toString());
      }

Thanks,
-Anil

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

2. AlertDialog lose on change rotation

I've an application with a MapActivity used how main activity. I
inserted an AlertDialog to show and edit a few infos. When I change
from portrait to landscape for open the keyboard, my AlertDialog is
detroied without replaced, then I must recall the command menu for
show again my AlertDialog.

Any suggest to mantain open the AlertDialog from portrait to landscape
and viceversa ?

thanks
--~--~---------~--~----~------------~-------~--~----~

3. Problem with simpleCursorAdapter, ListView backed by a managed cursor

4. Create new category

5. size of Bitmap

6. Not able to add account on email client of emulator(sdk r2)

7. How to re-install & sign android built-in applications