- Android — run in background #1166
- Comments
- SpanasGamesUnity commented May 20, 2016 •
- ArmandCloud commented Jun 5, 2016
- SpanasGamesUnity commented Jun 15, 2016
- claywilkinson commented Jun 16, 2016
- v-sag commented Aug 9, 2016 •
- claywilkinson commented Aug 9, 2016
- v-sag commented Aug 17, 2016
- lijuicsoft commented Sep 3, 2016
- valdowb commented Sep 24, 2017
- bbekec commented Apr 26, 2019 •
- DataGreed commented Jul 3, 2019 •
- DataGreed commented Jul 3, 2019 •
- DataGreed commented Jul 3, 2019
- Unity run in background android
- About
- Unity run in background android
- About
Android — run in background #1166
Comments
SpanasGamesUnity commented May 20, 2016 •
How to make this plugin run in background when app is minimized?
The text was updated successfully, but these errors were encountered:
ArmandCloud commented Jun 5, 2016
What feature you want to run in background.
SpanasGamesUnity commented Jun 15, 2016
Realtime Multiplayer — when app is paused ( minimize, click ad, call) it automatically disconnects (leave room).
claywilkinson commented Jun 16, 2016
This is because the unity game engine is paused when the activity is paused. There is not an easy way to work around this. Why do you want to have a player in a realtime game not be playing? It seems reasonable to have that player leave the game when they leave the app?
v-sag commented Aug 9, 2016 •
I really want to find out , too, actually. When someone calls, the person disconnects from the room. It will be really distrurbing for the users. Did anyone find a solution?
claywilkinson commented Aug 9, 2016
I don’t believe there is a work around at this time. It is the behavior of the underlying communications library within the Game Services SDK that when the activity is paused, the connection is closed. I have passed it along as an enhancement to change the behaviour.
I can see their thinking in the case of a fast paced game, for example a car racing, when the activity pauses you can’t see the road, and will crash anyway. But if the game play is slower, or you can effectively pause the game play, it should not disconnect.
Thanks again for the feedback.
v-sag commented Aug 17, 2016
Thank you claywilkinson. I am currently developing a realtime card game so it will be nice not to disconnect if someone calls.
lijuicsoft commented Sep 3, 2016
How to reconnect to a room in Google real time muliplayer with Unity3D ?
I create a quick game multiplayer connection
and Create With Invitation Screen
Connected to a room with one opponent
I dissabled my Ethernet connection of one device
I Enabled my Ethernet connection by
In my game each player’s data is sending to each other .
Before Ethernet disconnect it works perfect . After ethernet reconnection data is not getting to each other , but if one device left the room , following event will call.
How to detect , player disconnected from net and how to reconnect to same room properly
valdowb commented Sep 24, 2017
this is ridicoulous I have game with banner underneath when somebody click the banner will get disconnected from my multiplayer people will be discouraged to click on banner whole idea is that i am making game for get some money is there any way to fix it.
bbekec commented Apr 26, 2019 •
Same to me. This is the biggest problem for me.
I m also developing a card game. In a game room there is 13 episodes and 4 players. Players play each episode approximately 15 -20 minutes.
I designed the game that if there is no response from user in a time period, system sends data and game goes on. Although system is ok, If one changes screen, whole game and player disconnects.
As result, they are removing app from their device.
DataGreed commented Jul 3, 2019 •
I experience the same issue. This behaviour is very annoying for the players.
There is a native java solution, mentioned here:
I have edited BaseGameActivity.onStop() and have removed gamehelper.onStop(). So I stop gamesclient only in onDestroy. My game work perfectly also in background now.
And referenced here by another person who succeed in implementing it:
Though, you may also opt to try this suggested solution. Try editing BaseGameActivity.onStop() and remove gamehelper.onStop(). With this, gamesclient will only stopped in onDestroy. It might be a good option but I haven’t actually tried it
moving gameHelper.onStop to on destroy worked for me
That means the problem is definitely solvable.
I could try submitting a PR, but I am not good with java and I cannot find any mention of onStop or onPause methods in the play-games-plugin-for-unity repo.
Is there anyone here who could actually suggest where to start?
DataGreed commented Jul 3, 2019 •
@claywilkinson could you please tell us what methods the guys in the quotation above refer to? is it something from the library this repo uses as underlying communication library you were referring to? Where can I find this library to take a look at it and possibly alter the behaviour?
Could you please suggest where to start?
DataGreed commented Jul 3, 2019
it seems to me that fixing this issue is about commenting out this line in the library from NativeRealtimeMultiplayerClient .HandleAppPausing :
Could someone please clarify if that would solve the problem?
Источник
Unity run in background android
Note: Unsupported feature
This package is not an officially supported feature, and is provided «as is».
Use Background Download to download large files in the background on mobile platforms. It lets you fetch files that aren’t required immediately while caring less about application lifecycle. Downloads will continue even if your application goes into background or the Operating System closes it (usually due to low memory for foreground tasks). The Background Download package is not a replacement for HTTP clients. It has a specific focus on fetching lower-priority files for future use. Because the app assumes that these downloads have lower priority, download speeds can also be slower.
The Background Download is not integrated with the Addressable System or Asset Bundles and will require you write additional code to use in this context.
Limited platform support
Background Download only works on Android, iOS and Universal Windows Platform. It does not work in the Unity Editor, it only compiles.
For 2019.4 or newer
This feature is built as a package. To install the package, follow the instructions in the Package Manager documentation from a local folder or from a GIT URL.
For 2019.3 or older:
Clone/download this project from the 2019-3-and-older branch. Drop BackgroundDownload and Plugins folders into Assets in your Unity project. If you are building for Android, you have to set Write Permission to External in Player Settings. If you are building for Universal Windows Platform, you need to enable one of the Internet permissions.
The following table describes the package folder structure:
Location | Description |
---|---|
Runtime | Contains C# code and native plugins for mobile platforms. |
Samples | Contains example C# scripts explaining how to use this package. |
The example below shows how to call StartCoroutine(StartDownload()) to download a file during the same app session in a coroutine.
The example below shows how to pick up a download from a previous app run and continue it until it finishes.
Enum that lets control the network types over which the downloads are allowed to happen. Not supported on iOS.
- UnrestrictedOnly — downloads using unlimited connection, such as Wi-Fi.
- AllowMetered — allows downloads using metered connections, such as mobile data (default).
- AlwaysAllow — allows downloads using all network types, including potentially expensive ones, such as roaming.
Structure containing all the data required to start background download. This structure must contain the URL to file to download and a path to file to store. Destination file will be overwritten if exists. Destination path must relative and result will be placed inside Application.persistentDataPath , because directories an application is allowed to write to are not guaranteed to be the same across different app runs. Optionally can contain custom HTTP headers to send and network policy. These two settings are not guaranteed to persist across different app runs.
- System.Uri url — the URL to the file to download.
- string filePath — a relative file path that must be relative (will be inside Application.persistentDataPath ).
- BackgroundDownloadPolicy policy — policy to limit downloads to certain network types. Does not persist across app runs.
- float progress — how far the request has progressed (0 to 1), negative value if unkown. Accessing this field can be very expensive (in particular on Android).
- Dictionary > requestHeaders — custom HTTP headers to send. Does not persist across app runs.
- void AddRequestHeader(string name, string value) — convenience method to add custom HTTP header to requestHeaders .
The state of the background download
- Downloading — the download is in progress.
- Done — the download has finished successfully.
- Failed — the download operation has failed.
A class for launching and picking up downloads in background. Every background download can be returned from the coroutine to wait for it’s completion. To free system resources, after completion each background download must be disposed by calling Dispose() or by placing the object in a using block. If background download is disposed before completion, it is also cancelled, the existence and contents of result file is undefined in such case. The destination file must not be used before download completes. Otherwise it may prevent the download from writing to destination. If app is quit by the operating system, on next run background downloads can be picked up by accessing BackgroundDownload.backgroundDownloads .
- static BackgroundDownload[] backgroundDownloads — an array containing all current downloads.
- BackgroundDownloadConfig config — the configuration of download. Read only.
- BackgroundDownloadStatus status — the status of download. Read only.
- string error — contains error message for a failed download. Read only.
- static BackgroundDownload Start(BackgroundDownloadConfig config) — start download using given configuration.
- static BackgroundDownload Start(Uri url, String filePath) — convenience method to start download when no additional settings are required.
- void Dispose() — release the resources and remove the download. Cancels download if incomplete.
About
Plugins for mobile platforms to enable file downloads in background
Источник
Unity run in background android
Note: Unsupported feature
This package is not an officially supported feature, and is provided «as is».
Use Background Download to download large files in the background on mobile platforms. It lets you fetch files that aren’t required immediately while caring less about application lifecycle. Downloads will continue even if your application goes into background or the Operating System closes it (usually due to low memory for foreground tasks). The Background Download package is not a replacement for HTTP clients. It has a specific focus on fetching lower-priority files for future use. Because the app assumes that these downloads have lower priority, download speeds can also be slower.
The Background Download is not integrated with the Addressable System or Asset Bundles and will require you write additional code to use in this context.
Limited platform support
Background Download only works on Android, iOS and Universal Windows Platform. It does not work in the Unity Editor, it only compiles.
For 2019.4 or newer
This feature is built as a package. To install the package, follow the instructions in the Package Manager documentation from a local folder or from a GIT URL.
For 2019.3 or older:
Clone/download this project from the 2019-3-and-older branch. Drop BackgroundDownload and Plugins folders into Assets in your Unity project. If you are building for Android, you have to set Write Permission to External in Player Settings. If you are building for Universal Windows Platform, you need to enable one of the Internet permissions.
The following table describes the package folder structure:
Location | Description |
---|---|
Runtime | Contains C# code and native plugins for mobile platforms. |
Samples | Contains example C# scripts explaining how to use this package. |
The example below shows how to call StartCoroutine(StartDownload()) to download a file during the same app session in a coroutine.
The example below shows how to pick up a download from a previous app run and continue it until it finishes.
Enum that lets control the network types over which the downloads are allowed to happen. Not supported on iOS.
- UnrestrictedOnly — downloads using unlimited connection, such as Wi-Fi.
- AllowMetered — allows downloads using metered connections, such as mobile data (default).
- AlwaysAllow — allows downloads using all network types, including potentially expensive ones, such as roaming.
Structure containing all the data required to start background download. This structure must contain the URL to file to download and a path to file to store. Destination file will be overwritten if exists. Destination path must relative and result will be placed inside Application.persistentDataPath , because directories an application is allowed to write to are not guaranteed to be the same across different app runs. Optionally can contain custom HTTP headers to send and network policy. These two settings are not guaranteed to persist across different app runs.
- System.Uri url — the URL to the file to download.
- string filePath — a relative file path that must be relative (will be inside Application.persistentDataPath ).
- BackgroundDownloadPolicy policy — policy to limit downloads to certain network types. Does not persist across app runs.
- float progress — how far the request has progressed (0 to 1), negative value if unkown. Accessing this field can be very expensive (in particular on Android).
- Dictionary > requestHeaders — custom HTTP headers to send. Does not persist across app runs.
- void AddRequestHeader(string name, string value) — convenience method to add custom HTTP header to requestHeaders .
The state of the background download
- Downloading — the download is in progress.
- Done — the download has finished successfully.
- Failed — the download operation has failed.
A class for launching and picking up downloads in background. Every background download can be returned from the coroutine to wait for it’s completion. To free system resources, after completion each background download must be disposed by calling Dispose() or by placing the object in a using block. If background download is disposed before completion, it is also cancelled, the existence and contents of result file is undefined in such case. The destination file must not be used before download completes. Otherwise it may prevent the download from writing to destination. If app is quit by the operating system, on next run background downloads can be picked up by accessing BackgroundDownload.backgroundDownloads .
- static BackgroundDownload[] backgroundDownloads — an array containing all current downloads.
- BackgroundDownloadConfig config — the configuration of download. Read only.
- BackgroundDownloadStatus status — the status of download. Read only.
- string error — contains error message for a failed download. Read only.
- static BackgroundDownload Start(BackgroundDownloadConfig config) — start download using given configuration.
- static BackgroundDownload Start(Uri url, String filePath) — convenience method to start download when no additional settings are required.
- void Dispose() — release the resources and remove the download. Cancels download if incomplete.
About
Plugins for mobile platforms to enable file downloads in background
Источник