Static class in Java (Android) - use or not use

后端 未结 3 710
小鲜肉
小鲜肉 2021-02-08 12:38

Recently I have started development in Java for Android.

My idea is to create one static class which will load ton of stuff on the beginning and store results for a life

3条回答
  •  执笔经年
    2021-02-08 13:14

    Android provides a class called Application, which is will not be gc'ed as long as your Application isn't killed. Use this class for initialization, static classes as containers are somewhat ugly, but i can't pinpoint why that is.

    I only use them as containers for constants such as bitmasks which can't be expressed as EnumSets.

    As the other posts mention SharedPreferences: I think the preferences exist to store values, but not to load your structures that you need for you application. These structures should be loaded from a construct that represent or make up a model for your data's semantics.

提交回复
热议问题