Skip to content Skip to sidebar Skip to footer

I Want To Send Object Of My Model Class From Activity-one To Activity-three Directly. How Can This Will Be Achieved?

There are 3 activities named activity-one, activity-two and activity-three. Clicking next on activity-one takes you to the activity-two and then next on activity-two takes you to a

Solution 1:

Try this:

MyApplicationClassextendsApplication{
 privateModel model;
 publicstaticvoidsetModel(Model model){
 this.model=model
 }

 publicstaticModel getModel{
 return model
}
}

You can use generics to generify this function to handle any kind of model classes

Solution 2:

Another way is using

SharedPreferences

like this

In Activity one

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, 
MODE_PRIVATE).edit();
editor.putString("name", "Elena");
editor.putInt("idName", 12);
editor.apply();

In Third Activity

SharedPreferencesprefs= getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
StringrestoredText= prefs.getString("text", null);
if (restoredText != null) {
 Stringname= prefs.getString("name", "No name defined");//"No name defined" is the default value.
 intidName= prefs.getInt("idName", 0); //0 is the default value.
}

Post a Comment for "I Want To Send Object Of My Model Class From Activity-one To Activity-three Directly. How Can This Will Be Achieved?"