How to pass data between two activities in android?
Following is my code:-
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent)
Second I used SharedPreferences for that:-
For Pass Data:-
SharedPreferences gameSettings = getSharedPreferences("MyGamePreferences",MODE_PRIVATE);
SharedPreferences.Editor prefEditor = gameSettings.edit();
prefEditor.putString("UserName", "Guest123");
prefEditor.putBoolean("PaidUser", false);
prefEditor.commit();
For Getting Data in next Activity:-
SharedPreferences gameSettings = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
String s= gameSettings.getString("UserName", "Dipak");
Boolean b= gameSettings.getBoolean("PaidUser", true);
but data is not getting in next activity.
Why don’t you use mIntent.putExtra() for passing data to another activity?
Seeing your coding,you can get your sessionId in next activity using:(assuming your sessionId as integer)
And the way you are getting values from SharedPreferences is absolutely correct.I don’t know why you are not getting them in next activity.