Please check this code:
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Locale loc = null;
WeakReference<Locale> locWeak = new WeakReference<Locale>(loc);
String country = locWeak.get().getDisplayCountry(new Locale("", tm.getSimCountryIso()));
Log.i(TAG,"Country is: "+country);
The WeakReference
is a bit useless in here as I make a strong reference in "new Locale".
Can anyone please suggest a better approach to WeakReference
for something like this:
Locale loc = new Locale("",tm.getSimCountryIso());
The reason I use WeakReference
, is because I don't need to hang on to this Object
as it become useless as the app progresses. Secondly, I need to keep a clean memory as I will need to do some heavy tasks later on.
Thanks