Reputation: 693
Hi all I was wondering if is it possible to passing an object using intent to multiple classes. I know of passing only to 1 class.
Class1
Intent intent = new Intent(class1.this, class2.this)
intent.putExtra("item", itemMain);
StartActivity(intent);
Class2
Bundle retrieveData = getIntent().getExtras().getString("item");
What I want to do is pass the original itemMain to all classes like class 3,4,5
Upvotes: 0
Views: 159
Reputation: 3282
One possible solution is to have the object in question owned by the Application, not a specific Activity. Then all activities will have access to the object.
Upvotes: 0
Reputation: 26981
You should just use SharedPreference like this..
Here is how to insert data into shared preference..
SharedPreferences app_preferences =
PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = app_preferences.edit();
editor.putString("item", item);
editor.commit(); //Very important part
Here is how to get the information in all classes...
SharedPreferences app_preferences =
PreferenceManager.getDefaultSharedPreferences(this);
String item = app_preferences.getString("item", "No Item");
Upvotes: 1