There is a ton of questions related to the activity stack on the stack overflow, but I did not really see any that was given to me Answered the question. I am working on an online game that has 3 different activities (for now):
- Login / Register
- Menu (when logged in , "New game", "My stats", and a few other things ... I'm worried about the "new game" option for now.)
- Game
Socket connection occurs in login / registration activity, which creates a custom service that runs in the background. Since data can be accessed at any point of time, I am using socket class asynchronous response handler. It means that I will not have access to the current reference that receives any message at any time.
I have a need to figure out that when different message types are received then the current reference occurs when I send the message accordingly. For example, if a user has reached the sports screen (up to # 3) and receives a kind of message, then it will only tell the game screen that it is updated with a new game state. However, the user can be on the same game screen and receives a different type of message which "returns off screen # 3 and # 2 and logs the user back to the # 1 screen."
Actually, I am trying to figure out the best way to get current activity / context, to determine that this is the right reference for the current message and how to handle it.
You can use an ordered broadcast. Send broadcast to the service Register for each broadcast to be broadcast, whatever priority plan you feel is appropriate. There is an activity that receives the broadcast call abortBroadcast ()
then the transmission stops, in this way your service can send "eye shutdown" event.
You may not even need to order in this case. I feel that a broadcast receiver
registered by an activity will only be received if the activity is in the foreground (not paused)
I have written a bit more about the pattern, though for a slightly different situation (either handle an event in an activity or raise a notification
).
Comments
Post a Comment