0

I have a question about passing data between activities in Android. I tried to make an object Parcelable, it works but it's complicated to implement for every class. I want to try to store the value as a global and fetch it in the other activity. I know that we should avoid globals, but at the moment I don't have any other solution. Any advice? Maybe if I used a collection, it should be Parcelable, right??

Thanks in advance :)

2
  • Give us some code examples to work from. You can pass anything between activities with Intents. Commented May 4, 2011 at 15:02
  • Uhm seems to pass only Parcelable objects... But it's an hard work if object il composed by other objects... I have no code to show, but I wold simply define a class, instantiate a not parcelable object and pass the reference to another activity :) Commented May 4, 2011 at 16:38

3 Answers 3

2

I have a strong feeling that we misunderstand the whole conception of Activities. Looking at the intent's extra mechanism of passing data I can say Activity was invented like something all-sufficient w/o need of exchanging large amount of data between each other. But I still havn't got a point of android core designers. Check this thread, mb you'll find it helpfull.

Sign up to request clarification or add additional context in comments.

Comments

0

SharedPreferences is a global store accessible to all activities

http://developer.android.com/reference/android/content/SharedPreferences.html

... but as a key/value store it is no more capable than intent extras.

1 Comment

Uhm, I would keep a global reference to the object, not store it in a file...I don't know that class, but it seems to be used to save preferences, isn't it?
0

I have had success using a util class to hold private static objects that I need to pass around to other Activities within a single application. Don't be afraid to try it.

3 Comments

You mean extends Application??
No need for that. Just create a class that you can get/set your various objects to/from as needed. Your Activities can then call UtilClass.setCommonObject(Object o) and UtilClass.getCommonObject() to pass the data around.
Yep, it's how I'm doing now :) It works but, yeah, I'm afraid to use that cause I think it's not a clean solution...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.