Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8241983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:01:06+00:00 2026-06-07T21:01:06+00:00

I have an game application that users play between devices. I have added a

  • 0

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”

GAME

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);
        }  

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.

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

SERVICE

public class WakeCheck extends Service {

    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");

            <snip>
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:01:07+00:00Added an answer on June 7, 2026 at 9:01 pm

    Somebody presented this idea at Google I/O this year… When your gaming activity goes to foreground (onResume() for example), you set a boolean value in SharedPreferences to true to indicate that the user is playing. The WakeCheck will read this value and if it is true, it will not have to check remote plays. When the gaming activity goes to background (e.g., onPause()), it sets the value to false to communicate to WakeCheck that it needs to check the remote plays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple application with 'game' and 'article' pages that users can share
I have a facebook application (a two player game) that can post messages on
I have an air application that I'd like to turn into a multi-player game.
I have a facebook game application that is released at facebook platform at the
In my game application I have several different activities that all can be accessed
I have this game where balloons are coming from bottom and player has to
I have a game application for mobile. When signing new users up, I put
I have an application in C#/Winforms that lets users place objects on a grid
I have recently added game center to my application and everything worked great in
I am writing an application that will have some users on Internet Explorer 6.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.