Unity Android run in background - android

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)

Application.runInBackground is only for Webplayer (and PC, not sure about the last one though).
Unity runs as Activity in Android, hence it gets paused when it's loses it's focus. That's by (Android) Design and works as intended.
Topic link

Related

In Unity3D how turning off screen whithout sleep?

As in Unity3D turn off the screen without entering sleep mode, so that the application continues to work?
I don't believe it's possible to have Unity run in the background.
I don't know if this is still common practice, but in the past, many people simply draw a fully black screen to conserve power.
See: https://forum.unity.com/threads/application-runinbackground-is-not-working-on-android.117723/
Have you looked at - https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationFocus.html
OnApplicationFocus is called when the application loses or gains focus. Alt-tabbing or Cmd-tabbing can take focus away from the Unity application to another desktop application. This causes the GameObjects to receive an OnApplicationFocus call with the argument set to false. When the user switches back to the Unity application, the GameObjects receive an OnApplicationFocus call with the argument set to true.
You could implement this with the gameobjects you want to continue behaving as you like.

How do I stop the glSurfaceView when I used finish() in my android apllication

So I am making an android game, and so far it's working fairly well. I was using System.exit(0) to kill it, but I know that is an improper way to do it. So I used finish() instead, which does close the program. The problem is, that when I reopen it, the screen is blank. It seems that for some reason, the glSurfaceView isn't being released, and continues to run, and that upon reopening the game, it loses focus of it? The sounds and everything play, and my Logcats display information, so the game is in fact running, but just not the screen. Now before people start jumping on the (just let android take care of closing your app bandwagon) I have my reasons for doing so. For one, telling me that android is efficient enough to do this is a lie, otherwise we would not have the need to restart the devices every other day. Nothing more bothersome that a lag driven phone that can barely even handle an incoming call because it has so much shit on it running. So yea, I would like to be able to close the app.
So yea, how does one correctly to the glSurfaceView that it is time to close itself down? or to tell the Activities class that it needs to release it's handle to the glSurfaceView since closing the app sure doesn't do that.

Android app becomes unresponsive to touch

I have an app developed with Sencha Touch and phonegap. At one point, it downloads data from a server and, once it has received a successful response, it displays the next screen. I found, when bundling it up as an iOS app, that it would transition to that next screen, but not display anything, reporting low memory. So I simplified the layout of that next screen (the DOM structure was pretty complex) and it now works on the iOS simulators and on my iPhone.
However, in Android, I can see from the output of my console.log statements that it successfully retrieves the data and fires an event to display the next screen. It then sits around for ages before it displays that screen, even though my console.log statements show that the 'painted' event of that screen has been fired.
Eventually, the screen does show up, but all the controls on the screen are unresponsive to touch. Is it likely that I need to simplify the structure of that screen still further? As the iOS version received a low memory warning before I simplified the page structure, I suspect the Android version may have a similar problem, but I don't know how to monitor memory usage. In the Android version, shortly before the screen does eventually display I see the following in logcat:
UpdateFrameCache: pending style recalc, ignoring
And on the screen which is unresponsive, when I tap some (but not all) of the unresponsive controls, I see:
Got ACTION_DOWN but still waiting on stale event. Catching up.
Eventually, the app will just close itself, with:
Fatal signal 11 (SIGSEGV) at 0xbbbadbeef (code = 1)
Any help gratefully received.
If you perform intensive computations in the UI thread, it might explain why it takes so long.
Try using AsyncTask or a Service if you have some backgorund computations to do. Once they are done, update the interface in the UI thread.
Gordak

When Android app is not in focus but running the app becomes shaky

I have written an Android app that plays audio.
When the app is in focus (its UI is visible by user) the app works as expected and the audio is nice and solid. When the app is not in focus (user leaves the app's UI) but it is still running I hear the audio but it is shaky meaning if I open another app I see some choppiness in the audio for 1 second then it goes away.
What should I do to make sure even when my app is running in the back ground it is not disturbed with the operation other apps?
I am thinking this may be the place one should use services?
It looks like the best way to do this is to use a service.

Change UI automatically according to the cell phone

I am designing a prank app for android in which i want to show as if someone has called and then when the user answers the call it should play the recorded file. I have finished most of the things apart from 1 issue which i am facing currently.
1) As we all know the UI of every phone is somewhat different when they get a call, so i want to make sure that when running the app it should use the phone's default UI, so as to make sure it looks like a real incoming call.
I am uploading a picture so you'll have a better idea regarding my query. So as we can see that the UI is different for every phone, how can i make sure that when my app makes a fake call it uses the same UI which is displayed while getting a real incoming call.
Any help on the problem would be highly appreciated.
What you're trying to do is start the Android Dialler app, and then to change the functionality/have it do nothing while you play an audio file.
While you could enable the loudspeaker and play audio, you can't make the dialler stay active without a live call. An invalid number would fail, and an actual call would cost money.
What you want to do is actually very hard to achieve and the only thing you could try to do is to create your own fake dialler activities with different themes (according to major brands), detect the device manufacturer and then display a relevant one.

Categories

Resources