問題描述
假設我正在制作一個健身應用程序,您可以在其中進行鍛煉.配置完鍛煉后,您會想要保存它.如何添加此功能,以便當他退出應用程序并再次打開應用程序時,他可以查看他的鍛煉情況?
Say I was making a fitness app where you can make your out workout. When you have configured the workout you would want to save it. How do I add this function so that when he exits the app and opens it again, he can view his workouts?
我專門在 Android 上工作.
I am working specifically on Android.
這可用于保存本地游戲存檔和數據.
This could be used to save local game saves and data.
推薦答案
我相信 Kivy 有一個模塊可以解決這個問題.雖然它仍然(在撰寫本文時)是實驗性的.看這里:http://kivy.org/docs/api-kivy.storage.html#module-kivy.storage
I believe Kivy has a module that deals with this. Though it is still(at the time of writing) experimental. Look here: http://kivy.org/docs/api-kivy.storage.html#module-kivy.storage
根據 this,他們似乎正在使用 Pickle 來存儲數據.
如果由于某種原因這不起作用,自己使用 Pickle/cPickle 怎么樣?如果您不知道這些是什么,請立即使用 Google 搜索.然后您可以將用戶設置或鍛煉存儲在一個字典中并腌制該字典,保存info 作為一個簡單的文本文件到 sdcard,它根本不應該占用太多空間.
If that doesn't work for some reason, what about using Pickle/cPickle yourself? If you don't know what those are, Google them now. Then you could store user settings or workouts in a dict and pickle that dict, saving the info to the sdcard as a simple text file, which shouldn't take up much space at all.
據我所知,cPickle 是一個更快的 Pickle 實現,因為它是用 C 或 Cython 編寫的,我不確定.希望這對您有所幫助.
As far as I know, cPickle is a faster implementation of Pickle due to being written in C or possibly Cython, I am not sure. Hope any of this helps.
值得注意的是,可以將文本文件保存到 Android 設備.我最近使用 Kivy 制作了一個游戲,我就是這樣做的,以純文本形式存儲高分.
It's worth noting that it's possible to save text files to the Android device. I recently made a game with Kivy where I was doing just that, storing high scores in plain text.
這篇關于在 Android 上的 kivy 中保存應用數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!