title: Is there a way to get a current state of the application?
body: <p>I have an application that periodically checks the server for some flag.
  And then displays a message depending on the value of this flag.</p>
  
  <p>I don't want to display a message then the application is not in a front.
  And I use SharedPreferences to store the application state manually.
  In each activity I do something like:</p>
  
  <pre><code>@Override
  protected void onStart() {
      super.onStart();
      SharedPreferences.Editor prefs = context.getSharedPreferences("myprefs", getApplicationContext().MODE_PRIVATE).edit();
      prefs.putBoolean("appInFront", true);
      prefs.commit();
  }
  @Override
  protected void onPause() {
      super.onPause();
      SharedPreferences.Editor prefs = context.getSharedPreferences("myprefs", getApplicationContext().MODE_PRIVATE).edit();
      prefs.putBoolean("appInFront", false);
      prefs.commit();
  }
  </code></pre>
  
  <p>And this allows me to get a state of the application from "appInFront" preference:</p>
  
  <pre><code>SharedPreferences prefs = context.getSharedPreferences("myprefs", Context.MODE_PRIVATE);
  boolean appInFront = prefs.getBoolean("appInFront", true);      
  </code></pre>
  
  <p>But may be exists native method or way to get a current state of the application (is the application in a front or is it in a background)?</p>