Android : Static variable null on low memory

前端 未结 7 2372
轮回少年
轮回少年 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:54

    I store a User object and a Client object in my static scope. I have noticed from time to time the reference becomes null. So now in my getters I check to see if this value is null and if so I restart the app.

    Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    context.startActivity(i);
    

    I could have also chosen to reload the Client because I store the Access Token in prefs however I do so much initialization that I decided restarting the app would the best idea.

提交回复
热议问题