When to save data to database, onPause() or onStop()?

后端 未结 3 733
挽巷
挽巷 2020-12-09 10:23

I know this question has been asked a million times, I myself though that I already knew the answer and that the correct one was that the only guaranteed call is to onPause(

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 11:22

    • If you want more safety, storage in onPause.
    • If your data is so big that you have to storage it for several seconds, you may open a background Service (e.g. IntentService) to save.
    • You can also check the system version in your code and choose when to save. if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.ICE_CREAM_SANDWICH){}
    • In most situations this rule of when to save will not be changed by some customed os. But of course there can be some other os which certainly changed it. So the most important thing in android development is that u need to know that everything can be different in different phones.

提交回复
热议问题