Android service - only when app is not running
<p>I have an game application that users play between devices. I have added a Service that intermittently checks if a remote  player has made a move and then notifies the local user that it's now his or her turn.  I use this code in the games's main activity to fire off a the service based on the user's preferences for "intermittent"</p>

<h2>GAME</h2>

<pre><code>if (Settings.AlarmInterval != 0) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.add(Calendar.MINUTE, (int)(      Settings.AlarmInterval/1000/60));

            Intent myIntent = new Intent(mCtx, WakeCheck.class);

            pendingIntent = PendingIntent.getService(mCtx, 0, myIntent, 0);

            AlarmManager alarmManager = (AlarmManager)mCtx.getSystemService(mCtx.ALARM_SERVICE);
            alarmManager.cancel(pendingIntent); // cancel any previous alarms
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,  calendar.getTimeInMillis(), Settings.AlarmInterval, pendingIntent);
        }  
</code></pre>

<p>This works just fine.  However, even if the local user is currently playing
the game the service wakes up and checks to see if a move has been played. I'd like for
the user to be notified only when the game is NOT currently being played.</p>

<p>How can I detect within my WakeCheck service, that the game is on and running and there's no need to check remote plays?</p>

<h2>SERVICE</h2>

<p>public class WakeCheck extends Service {</p>

<pre><code>    private triDbAdapter mDbHelper;
           private static final int CHALLENGE = -2;

@Override
public void onCreate() {
// TODO Auto-generated method stub
//Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
}



@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
//Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
return null;
}



@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mDbHelper.close();
//Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
}



@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    Cursor c;
    triDbAdapter mDbHelper = new triDbAdapter(this.getApplicationContext());
    mDbHelper.open();
    ServerCommunication sComm = new ServerCommunication(this.getApplicationContext());
    c = mDbHelper.fetchAllGames();
    Log.d("WAKE","Checking Game Status");

            &lt;snip&gt;
}
</code></pre>
