I have used this tutorial to save session. I still don't understand how to get this data from another activity.
public HashMap<String, String> getUserDetails(){
HashMap<String, String> user = new HashMap<String, String>();
user.put(KEY_FULLNAME, pref.getString(KEY_FULLNAME, null));
user.put(KEY_EMAIL, pref.getString(KEY_EMAIL, null));
// return user
return user;
}
I found out people are using intent to send it to another activity like in this link. Is there a simple way to get the data like i call methods from another activity(import the class, then give a variable var
for that class, and call the method like var.theMethodFromClass()
).
Update
public SessionManager(Context context){
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}
this function is in my SessionManager class, how can i use it directly, without initializing all variables again, as they are already initialized in the activity in order to be used.
the full code of SessionManager.class is in the first link
You are already saved your data in the SharedPrefernces
so why you need to send it from one Activity
to another Activity
..Try to open the SharedPreference
file in Another Activity and Use it as you like..
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments