Erenwoid
Erenwoid

Reputation: 993

Passing values between activities in Android

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 :)

Upvotes: 0

Views: 1258

Answers (3)

ernazm
ernazm

Reputation: 9258

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.

Upvotes: 2

Haphazard
Haphazard

Reputation: 10948

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.

Upvotes: 0

Jim Blackler
Jim Blackler

Reputation: 23169

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.

Upvotes: 0

Related Questions