Unity Android run in background

Started by
1 comment, last by Patrick-GameSparks 7 years, 10 months ago

I am building a simple game where 2 people can duel against each other. I am using GameSparks as a back end. My problem is, that whenever player #1 casts a spell that is channeling, player #2 can see the channeling only when his screen is turned on and in focus.

Whenever player's #2 screen turns off, the app is not active anymore so the spell is not being casted at him. When player #2 turns on the screen, the channeling starts, but player #1 was already done channeling a while ago.

I assume that is related to the way Android system works. It puts apps that are not in focus on pause.

My problem now is, how can I make sure that player #2 gets a notification whenever he is hit by the spell without a need to use any third party service to keep the app alive (to avoid huge battery consumption) and also without a need to use push notifications (as from what I've heard, if there is a high load, the push doesn't happen right away, since there is a queue)

Advertisement

Android apps can create a "persistent notification" in the notification bar.

I would suggest that you use the notification system to display a "so and so is casting a spell" notification while that's happening if the app is in the background.

Separately, Android allows you to start Services, which can run in the background and communicate with servers, without having the same aggressive suspension as UI-facing activities.

This can be used for things that need to communicate while the app is in the background. However, don't abuse Services to do things like continually run a game update loop -- that will drain the battery very fast!

enum Bool { True, False, FileNotFound };

Hi Zatokar,

Have you updated to the latest sdk? What version are you running? If you log a ticket with our support team over at GameSparks we can get this issue resolved for you. Additionaly, if upgrading to the latest sdk doesn't solve this, you could set up custom messages and listeners to notify the client when certain events are fired.

Best Regards, Patrick.

This topic is closed to new replies.

Advertisement