i'm working on a game for android, i got a problem :
when i kill task via task manager on android the playerperf from unity not working, i had used OnApplicationQuit(), but it didn't saved when i kill task via task manager, but quit from quit button (which call Application.Quit()) works fine on android.
Anyone have the solution how to make playerperf work when user kill task via android task manager ? i'm using C# and Unity 5
In the Android activity lifecycle you can't really depend on your application being available to safely store data past its onPause state. The practice for native Android apps is to save any data you need by overriding the onPause() function.
In Unity, this maps to OnApplicationPause.
I wouldn't count on being able to safely guarantee any data can or will be saved past this point.
Related
i have a unity mobile multiplayer game, using firebase for matchmaking,
when the users press the play button it adds them as available for machmake
mDatabaseRef.Child("matchMake").Child(auth.CurrentUser.UserId).Child("playerName").SetValueAsync(auth.CurrentUser.DisplayName);
and remove them when the user press the cancel game search button, but i also want to remove them when they close the app (even if they don't press the cancel game button) using
private void OnApplicationQuit()
{
removePlayer();
}
void OnApplicationPause(bool pause)
{
removePlayer();
}
public void removePlayer()
{
mDatabaseRef.Child("matchMake").Child(auth.CurrentUser.UserId).RemoveValueAsync();
}
so what i want is to keep them in matchmake if they add the app in background (and thinking of informing them about finding game with push notifications) but remove them if they close the app from App Switcher (or even if the system quit it to free up resources).
The problem is that while i can remove the "removeplayer" from OnApplicationPause that called when the app goes in background, it doesn't call the OnApplicationQuit if the app close from app switcher, this behaviour is kinda correct according to the documents
Warning: If the user suspends your application on a mobile platform, the operating system can quit the application to free up resources. In this case, depending on the operating system, Unity might be unable to call this method. On mobile platforms, it is best practice to not rely on this method to save the state of your application.
is there any way to do what i want ?
Thanks !!!
Firebase Realtime Database has so-called onDisconnect handlers that allow you to send a write instruction to the server while you are online, that the server then executes once it detects that the client has disconnected.
Somehow onDisconnect is not documented for the Unity, so I recommend checking the Android documentation to learn how onDisconnect works, and then implementing it based on the reference documentation for onDisconnect in Unity.
I have Win32 desktop bridge application that uses background task to receive push notifications from WNS. I use UWP background task APIs over C++-WinRT
I'd like to be able to receive push notifications even when OS is in sleep so that it wakes up and the app handles push notification. By default OS does not wake up. It did only after manually changing settings value in System->Battery->See which apps are affecting your battery life->Click my app ->Uncheck Let Windows decide option (by default it is always checked) and check Allow the app to run background taks. Now I'd like to do this is manual work on code for better user experience.
RequestAccessKindAsync API allows to let user to change above setting value by showing popup notification to the user and I could do it without any problem in UWP C# sample app. But same code does not show pop notification from my desktop bridge over C++-WinRT. It simply returns false value for below code
auto result = co_await BackgroundExecutionManager::RequestAccessKindAsync(BackgroundAccessRequestKind::AlwaysAllowed,
L"App needs to use background to catch push notifications while device is in sleep");
Can anyone confirm that RequestAccessKindAsync API works from desktop bridge? If not then how I can make sure OS and the app will always be able to wake up from sleep when it receives push notification?
UPD: Raised request to enable this API from desktop brige here
This is a missing feature. When we designed this API a couple of releases ago we didn't consider desktop bridge apps would be calling it - but clearly there is a use case for supporting this. I have notified the team about this gap, but I'd also encourage you to log a feature request here: https://wpdev.uservoice.com/
Two possible workarounds:
(1) you could add a dummy/empty UWP foreground app to your desktop bridge app. You can then launch this on startup and request the background access from there. This will be a bit ugly, but you could make it look like a splash screen :-)
(2) you can instruct the user to go into the Settings app to set your app to always allowed. You can help them do that with a deep link to the battery save settings, but they will still need to manually flip the switch.
Scenario. I want to make UWP(8.1/10) library (somekind of remote diagnostic of app) which works with my server. Is it possible to keep tcp/ip connection in background as long as possible?
I know about two things:
Run while minimized
Run background tasks indefinitely
But if I want to insert my library into some app and then upload it in Store, it won't work, am I right?
However, developers writing UWP apps for personal use (that is, side
loaded apps that won't be published in the Microsoft Store), or
developers writing Enterprise UWP apps, may want to use all resources
available on the device without any background or extended execution
throttling. Line of business and personal UWP applications can use
APIs in the Windows Creators Update (version 1703) to turn off
throttling. Be aware that you can't put an app into the Microsoft
Store if it uses these APIs.
Also I have read about ExtendedExecutionSession when app minimized from these questions:
Run Background Task Indefinitely in UWP
extendedExecutionSession : Can we run UWP like Desktop app without
Suspending?
But I'm still confused. So, can I make library for UWP(8.1/10) with long-running background tcp/ip connection and insert into app which will be uploaded in Windows Store?
I have an UWP application, which executes some long running task for up to 1 or 2 hours. When I minimize my UWP application, the status of my application turns to Suspended and my long running task is suspended too. I wonder whether I could keep my long running task doing its job while my UWP app is suspended. I want this work for desktop, tablet and laptop.
Seeing from this post, using ExtendedExecutionSession can only run a task less than 10 minutes if no wall power for desktop; for tablet or laptop, it could run as long as screen is on, up to the battery.
I also looked into background task or background transfer - it seems background task not supporting work like mine; and background transfer only supports file transfer.
The only option I could see now is a win32 application, I could include it as part of my uwp application. And I could launch a process for the win32 application, pass info from uwp to this win32 by app service connection, then when my uwp application is suspended, my win32 application could go on working on the long running task. After my long running task is done, I can activate my uwp application to resume.
Is there any other option I could take a look here? Is there anything wrong to use the win32 process to run my long running task when my uwp is suspended? I have experimental code to package them in one appx, uwp can launch win32 process, and they can communicate to each other. Any input or concerns or suggestions are welcomed!
If you are writing your UWP app for personal use/sideloading, and NOT the app store.. this MSDN link answers your question.
From that link:
"If you are developing an app that is not intended to be submitted into the Microsoft Store, then you can use the ExtendedExecutionForegroundSession with the extendedExecutionUnconstrained restricted capability so that your app can continue to run while minimized, regardless of the energy state of the device. "
I'm learning Win 10 UWP and my goal is to write an SQLite database entry every 15 minutes using a background task.
My question is, what happens to the background task when the user shuts down the system and restarts it later on?
As I can understand, the user has to start the application again manually to register the background task again. Or is the background task somehow registered somewhere and restarts when the system is back up again without having to manually restart the background task again?
Once you've registered your background task, it stays around even after the computer reboots. The user doesn't have to launch your application again.