I have 3 modules: mod1
, mod2
and mod3
. Module mod1
has dependencies mod2
and mod3
.
I want to have one String (in particular it will be UserAgent because all 3 modules HTTP-talk to some server and all 3 should have the same user agent set) to be shared among those 3 modules.
One way to do this is to make a public class with methods to write and read information.
public static String readnote(Context context, String str) {
if (context == null) throw new RuntimeException ("Context is null");
SharedPreferences sp = context.getSharedPreferences("somenameyouchoose", 0);
String mycontent = sp.getString(str);
return mycontent;
}
public static String writenote(Context context, String str) {
if (context == null) throw new RuntimeException ("Context is null");
SharedPreferences sp = context.getSharedPreferences("somenameyouchoose", 0);
SharedPreferences.Editor editor = sp.edit();
editor.putString(str);
editor.commit();
return str;
}
Then you can writenote (this, "myUserAgent") and readnote (this, "myUserAgent").
If you use intent, another aproach is to use intent.putExtra.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With