Android : Static variable null on low memory

前端 未结 7 2332
轮回少年
轮回少年 2020-11-29 02:44

I have an application which has some static variables. These variables are stored in an independent Class named DataContext. These variables are initialized from raw files a

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 02:58

    1. You can't. Android needs to free up memory from time to time. Imagine if all applications had a ton of static data that is supposed to be resident forever - how would you fit that in memory? It's a mobile phone. It doesn't have virtual memory.

    2. (and 3): Anything that is intended to be persistent needs to be stored, either via SharedPreferences, a Sqlite database, or a file.

提交回复
热议问题