Home > Back-end >  Passing data from Activity to another one
Passing data from Activity to another one

Time:10-21

In my case i have 3 activities A,B,C i start on A and go to B but when i start C activity i want to get data from A activity.

A: login page that get a session token that i get from an API.

B: home page that contains some card view that they have on click listener which start C activity.

C: activity that i want to get data from A (API session token) so i can get some info in my text views.

I did try to use Intent intent=getIntent(); String session_token=intent.getStringExtra(Loginscreen.EXTRA_TEXT);

Any help would be appreciated thank you.

CodePudding user response:

Use sharedPreferences for such scenarios rather than sending data with intents.

You can have similar code inside activity A where you have the session token:

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("session_token",session_token);
editor.apply();

And then inside activity C

 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 session_token = preferences.getString("session_token","");

Hope it works for you.

  • Related