Android(安卓)Activity class and static members
In one of my Android application, I was storing some data in a static member variable. After few hours of inactivity, when I used to open the application, I would see that all the data I had stored in the static member variable was gone.
I know about the Android Activity life cycle and that Android can unload Activity class if it is not active. However I did not think that it would reset all static members too. So I had three options to persist data -
- Store it in preferences
- In a file (local or on external media)
- In the database
- In the Android application class
See this articlefor more details about data storage options in Android. Since the data is not large and I did not already have Android database created for this app (this app does use database, but it’s HTML5 database), I decided to use option #4. Storing in application class also suited this application because I do not need the data if Android or user kills the application.
So, be very careful when using static variables in Activity class.
-Ram Kulkarni
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer