tags:

views:

136

answers:

2

Can I pass a singleton class's object from one activity to another activity using intent? I am using singleton class as imageclass img = imageclass.getInstance();, so i need the img instance for another activity, how can i pass an object instance in Android?

Thanks all

A: 

I advise you read up on content providers as the route to take to share objects, its a fundamental part of android programming. I would not be trying to pass an intent as a means to share data.

A content provider makes a specific set of the application's data available to other applications

Source: http://developer.android.com/guide/topics/fundamentals.html

Further info + tutorial : http://developer.android.com/guide/topics/providers/content-providers.html

JonWillis
@plz give some example for me because i am fresher in android thanks
sivaraj
Sorry but i'm the same, i am fresh to it as well. But i have finished some background reading so i know the above is true, i have just yet not needed to use it.Nonetheless i have included a tutorial/further info on them in my answer.
JonWillis
Content providers aren't really there "to share objects".
CommonsWare
A: 

I have no idea what imageclass is.

Generally speaking, you don't really want to pass too much complicated between activities. Think of activities as being like Web pages of a Web app, and the Intents as being the URLs you use to launch Web pages. You do not typically pass arbitrary objects in a URL. Instead, you perhaps pass keys, identifiers, or other information in a URL, so the server can access the right arbitrary objects that are kept on the server.

Similarly, via Intent extras, you can pass simple data between activities, but you would not pass images, databases, business objects, or other complex materials that way. Instead, either keep those within a single activity, or maintain them in some central store (e.g., database, Service, custom Application subclass) and pass an identifier from activity to activity.

JonWillis' recommendation of using a content provider might work, but that is designed for fairly simple data structures, not your existing arbitrary objects.

CommonsWare