Skip to content Skip to sidebar Skip to footer

Is There A Way To Send Data Between Activities Without Using Intent?

I have a username unique to every user that I want to send to a certain activity, but I don't want to use intents: //create an intent and sends username Intent intent = ne

Solution 1:

I guess you want to have a particular data available between activities. One of the methods to achieve this is by making use of the SharedPreferences.

From your first activity(RegisterOwner)

SharedPreferencesmySharedPreferences=this.getSharedPreferences("MYPREFERENCENAME", Context.MODE_PRIVATE);
SharedPreferences.Editoreditor= mySharedPreferences.edit();
editor.putString("USERNAME",usernam);
editor.apply();

Once you do this the username is stored in the shared preferences. Now you have this data available throughout your app.

So from the Owner activity you can retrieve this as follows:

SharedPreferencesmySharedPreferences=this.getSharedPreferences("MYPREFERENCENAME", Context.MODE_PRIVATE);
Stringusername= mySharedPreferences.getString("USERNAME", "");

Post a Comment for "Is There A Way To Send Data Between Activities Without Using Intent?"