且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android应用程序在后台运行时保存数据

更新时间:2022-12-27 11:32:16

如果问题是在backgroud中您的应用程序被android破坏,则标准方法是将数据保存在您的onDestroy()函数中主要活动,并在再次打开to应用程序时(使用捆绑包)在onCreate方法中检索此数据.

If the problem is that your app is destroyed by android when in backgroud, the standard way to do would be to save data in the onDestroy() function of your main activity, and retrieve this data in the onCreate method when to app is opened again ( using the bundle).

如果您希望即使在手机关闭的情况下也能保留数据,则可以考虑使用永久存储选项,例如数据库.看看 http://developer.android.com/guide/topics/data/data-storage.html

If you want the data to persist even when the phone is turned off, you can considere permanent storage options like a database. Have a look at http://developer.android.com/guide/topics/data/data-storage.html

最后,如果您想要一种在后台继续运行的方法,可以看看Service类.但是,如果需要您提供更多的编码,以便能够在您的服务和活动之间进行交流

Finally, if you would like a way to keep running in background, you could have a look at the Service class. But if would demand some more coding from you to be able to communicate between your service and the activity