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

  • SEARCH
  • Home
  • 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 8939429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:49:14+00:00 2026-06-15T10:49:14+00:00

I am developing a Multiplayer Online word game on Android and would like to

  • 0

I am developing a Multiplayer Online word game on Android and would like to implement a thread that checks for server side events like the following:

  • Player join a game.
  • Player left a game.
  • Player won a game.
  • etc…

The thread will be responsible for listening for all kinds of events and dispatching events to the responsible activity If it’s visible to the user.

In other words to be more clear, I’ve got a list of event and each activity must register to a subset of these events.

Events:

E1 – E2 – E3 – E4

Activities:

  • Activity 1 interested in E1 and E2.
  • Activity 2 interested in E1, E2 and E3.
  • Activity 3 interested in E3 and E4.

I am asking about the best design approach to implement a thread that runs in the background and can dispatch events to all activities?

Some Ideas:

-Implement an AsyncTask on the application level.

-Send broadcast intents to a custom actions.

-A service is not the best approach because it should be created to run in the background when the user is not interacting with your application.

Can you propose a best practice approach?

  • 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-15T10:49:15+00:00Added an answer on June 15, 2026 at 10:49 am

    A good approach for this is to use a Service combined with AsyncTasks.

    While a Service is useful while the user is not interacting with your application, that certainly isn’t its only use. A Service is the logical home of anything that does not require a UI.

    In data driven apps, I have used Services as API adapter layers. It is nice because I can launch it from any activity without worrying about whether it is already instantiated or whether I need to do any cleanup work after I’m done. The framework manages the service’s lifecycle and tracks clients.

    I think your case is similar. Each activity can use bindService and unbindService to register for updates as long as it needs. The service will continue to do its thing as long as any Activity is bound. The service can keep track of which activities need updates using the Intents received in onBind and onUnbind, and send them updates via specific Intents, or, more appropriately, the service can fire broadcast intents and the Activities can register for what they need.

    Within the Service, you would run AsyncTasks (probably running them on AsyncTask.THREAD_POOL_EXECUTOR so you get more than one thread) to do your updates. Remember that the service itself is launched on the UI thread.

    Another nice benefit to using a service is that it doesn’t require an Activity to run. One use for this that comes to mind is post-shutdown cleanup. If you need to post scores or analytics or something when the user exits, you can allow the activity to close quickly and finish the longer-running work in the background.

    Activities can request those longer individual tasks from the Service using startService, and the service won’t exit until it calls stopSelf (or stopSelfResult).

    The combination of start/stop and bind/unbind really allows for clean management of the service. It will run when and only when it needs to, and you can keep all your API access in one place.

    Edit:

    As if this wasn’t a stout enough wall of text, I’ve come up with another good reason to use a Service. From the developer guide on processes & threads:

    Because a process running a service is ranked higher than a process
    with background activities, an activity that initiates a long-running
    operation might do well to start a service for that operation, rather
    than simply create a worker thread—particularly if the operation will
    likely outlast the activity…

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

Sidebar

Related Questions

I am developing a multiplayer game server with Twisted. It's a simple game that
I am developing a multiplayer game with more than 2 players. I would like
In a multiplayer game I'm developing, we have a few values that are floating
I'm developing a game for iOS that should include the multiplayer. It's not a
I'm developing multiplayer game and I have a server written on asp.net . Game
I am developing a multiplayer game for Android. There are plenty of game engines
I'm currently developing a simple multiplayer game app for Android and I need to
I'm developing a multiplayer game that is going to work by transmitting data over
I am developing a multiplayer gaming server that uses Django for the webserver (HTML
we are developing a database backend for a multiplayer game. The server is written

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.