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

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 11  |  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. Handling asynchronous task completion when Activity is in or out of focus
  2. public class MyActivity {
  3.     private boolean displayAlertOnStart = false;
  4.  
  5.     protected void onStart(){
  6.         super.onStart();
  7.         if (displayAlertOnStart){
  8.             displayAlert();
  9.             displayAlertOnStart = false;
  10.         }
  11.     }
  12.  
  13.  
  14.     private void handleTaskCallback() {
  15.         if (activityIsOnTop()) //How do I get this???
  16.            displayAlert();
  17.         else
  18.            displayAlertOnStart = true;
  19.     }
  20.        
  21. public class MyActivity {
  22.     private boolean displayAlertOnStart = false;
  23.     private boolean activityInAStartedState = false;
  24.  
  25.     protected void onStart(){
  26.         super.onStart();
  27.         activityInAStartedState = true;
  28.  
  29.         if (displayAlertOnStart){
  30.             displayAlert();
  31.             displayAlertOnStart = false;
  32.         }
  33.     }
  34.  
  35.     public void onStop(){
  36.        super.onStop();
  37.        activityInAStartedState = false;
  38.     }
  39.  
  40.  
  41.     private void handleTaskCallback() {
  42.         if (activityInAStartedState)
  43.            displayAlert();
  44.         else
  45.            displayAlertOnStart = true;
  46.       }    
  47. }