question

hromoydron avatar image
hromoydron asked

I don't want application work in background

Hi!

PlayFab in InitializeHttp() set Application.runInBackground to true.

And never set it to false.

I don't want my game to work in background.

What should I do?

Can I write Application.runInBackground = false when I get response from server and than when I send response set to true again?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
1807605288 avatar image
1807605288 answered

Yes, you can change this, but you will experience some subtle changes in functionality.

First, our code is open source, so you can simply comment out that line in our code, or change that line to " = false". You can also set it yourself in your own code, though, you'll have to be careful about timing. I'll see if I can make a small tweak to the next publish to make this a bit simpler for you.

Second, the reason our code forces runInBackground to true is that your API calls take time, and if the user drops focus in the middle of an API call, that API call will appear to fail. But, the PlayFab server will have done all the work, and so the error you get won't match reality.

SO, you'll have to code your game with the expectation that every API call could succeed, and report failure. It will be rare obviously, but it becomes likely to happen whenever the app loses focus.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

hromoydron avatar image hromoydron commented ·

So if I set runInBackground = true when I make API call and set runInBackground = false in callback all would work fine, yeah?

0 Likes 0 ·
1807605288 avatar image 1807605288 ♦ hromoydron commented ·

Wow, that's...

Maybe? That's beyond my expertise. You'd have to ask Unity what happens if you toggle that on and off all the time.

Best case it might work as expected, worst case it will just be mostly/always on, or mostly/always off, which... is worth experimenting with at any rate.

Please contact Unity about that one and let us know how it turns out. I might integrate something like that into the SDK itself if Unity doesn't warn you away from it.

0 Likes 0 ·
1807605288 avatar image 1807605288 ♦ commented ·

I have been told by a coworker that it's probably irrelevant.

https://forum.unity.com/threads/application-runinbackground-is-not-working-on-android.117723/

That flag does nothing for phone devices. It only applies to web and pc.

0 Likes 0 ·
hromoydron avatar image hromoydron 1807605288 ♦ commented ·

So now I just doing WebGL version of my game for play in browser on pc.

0 Likes 0 ·
1807605288 avatar image 1807605288 ♦ hromoydron commented ·

Aha, ok. Then we're back to the suggestion of "try it and see what happens".

Good luck!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.