Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pstreef · Jun 18, 2014 at 01:09 PM · c#androidthreadingcallback

C# How to wait on callback, should I use threading?

When minimizing my android game I want to save certain data to the cloud. This works fine when using a button (exit button will save and then exit), but to make cheating a little harder I also want to save the game when the player minimizes.

When this happens unity calls: OnApplicationPaused() where I can handle this saving. Unfortunately, the play-games-plugin-for-unity that I use, uses a callback which is called when saving is finished, which means the message pipeline continues during the saving and the app is minimized before saving is finished.

My question is how do I hold the app from minimizing untill my callback is called and the saving is finished.


This is a rephrasing of my previous question here. I think I made the question a bit to specific there to get an answer. Since this is also my last remaining issue I would really love a fix for this as soon as possible!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AndyMartin458 · Jun 18, 2014 at 03:38 PM

Saving to the cloud is a pretty difficult thing to do when an app goes to sleep. I'm not as familiar with Android, but on iOS, you have to add in unmanaged code to run in a background thread when the app is put to sleep. There is no way to simply stop an app from going to sleep: imagine the user is receiving an urgent phone call and you say "oh no, I want to save your data first." That's why it must happen in some kind of background thread, but that thread is going to have to be managed by the operating system, not Unity. Try to draw a diagram of the saving system you described is currently happening and think of potential pitfalls that can make that diagram stop functioning.

Another option is to save locally when the app goes to sleep. Try pushing to the cloud only when the game is open. I currently play a game that only saves when I tell it to. Putting the game to sleep isn't super-safe because if the app is killed, I lose my progress. I'm ok with this setup though because in general I would rather find a save point.

Every game is different, but I think you should rule out saving to the cloud when the app goes to sleep because of all the situations possible such as: the user has no internet connection, etc. Try instead to make your game as consistent as possible at coming back into the same state after waking from sleep.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pstreef · Jun 19, 2014 at 07:14 AM 1
Share

Thank you very much! This is something I can work with. I think I'm going to look into saving locally and maybe destroying the save state on load (just so that the user can't reload a save state multiple times).

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to wait for callback in OnApplicationPause on android 0 Answers

Multiple Cars not working 1 Answer

Can't start a Handler on the main thread 1 Answer

Distribute terrain in zones 3 Answers

Access android IR blaster 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges