Android App with two solution for passing data between activities (No Intent Extras Please!)
public class A {
public static LinkedHashMap<String,String> hashStore = new LinkedHasMap<String,String>();
public void doHttp(){
//Some HTTP call and store some json value
hashStore.put("data","jsonKeyValue");
}
public void onDestroy(){
hashStore.remove(key);// remove data key
hashStore.clear();
}
}
public class B {
public void getHttp(){
//Some HTTP call
String extra = A.hashStore.get("data");
}}
// SharedPreference Call
public class A{
SharedPreference hashPref ; //declaration on onCreate
public void dohttp(){
//Some Http and Store value in SharedPreferences
hashPref.put("data","jsonkeyvalue");
hashPref.apply();
}}
public class B{
SharedPreference hashPref ; //declaration on onCreate
public void getHttp(){
//Some HTTP call
String extra = hashPref.get("data");
}}
- Which one is better option to reduce memory leaks ?
- If i store more than 30-40 keys which one would be preferrable ?
- If i use sharedpreferences won't i eat the performance while validating and updating the keys ??
- Is there any alternative that i could use instead of these two solutions ? (Don't mention Intent Extras here.)