Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Best-practice: Update ArrayAdapter continously
  2. private void startListUpdateThread()  
  3. {
  4.     Thread ListManageThread = new Thread() {
  5.         LinkItem listItem;
  6.         public void run() {
  7.             Log.d("DL", "List Update - start");
  8.             while(true)
  9.             {  
  10.                 runOnUiThread(UpdateGUIList);
  11.  
  12.                 try {
  13.                     Thread.sleep(1000); //5Sekunden!
  14.                 }
  15.                 catch (InterruptedException e) {
  16.                     // TODO Auto-generated catch block
  17.                     e.printStackTrace();
  18.                     Log.e("DL", "ERROR: InterruptedException - " + e.getMessage());
  19.                 }
  20.             }
  21.         }
  22.     };
  23.     ListManageThread.start();  
  24. }
  25.  
  26. private Runnable UpdateGUIList = new Runnable() {
  27.  
  28.     @Override
  29.     public void run() {
  30.         mFileAdapter.notifyDataSetChanged();
  31.     }
  32. };
  33.        
  34. private void startListUpdate()
  35. {
  36.     handler.removeCallbacks(UpdateListUI);
  37.     handler.postDelayed(UpdateListUI, 1000); // 1 second  
  38.  
  39. }
  40.  
  41. private Runnable UpdateListUI = new Runnable() {
  42.     public void run() {
  43.         //Remove Elements first
  44.         removeDeletedItemsFromList();
  45.  
  46.         //Update Adapter
  47.         mFileAdapter.notifyDataSetChanged();
  48.  
  49.         handler.postDelayed(this, 1500); // 1,5 seconds
  50.     }
  51. };
  52.        
  53. AlarmManager mgr = (AlarmManager) arg0.getSystemService(Context.ALARM_SERVICE);
  54. Intent intent = new Intent(arg0, TestService.class);
  55. PendingIntent pi = PendingIntent.getService(arg0, 0, intent, 0);
  56. mgr.setRepeating(AlarmManager.RTC_WAKEUP, 2000, 2000, pi);