File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes How to pass POJOs / data / values between activities? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to pass POJOs / data / values between activities?" Watch "How to pass POJOs / data / values between activities?" New topic
Author

How to pass POJOs / data / values between activities?

James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

I have 2 activities

The first one grabs contact details from the ContactsContract provider

The second one displays values on a map

In the first activity, how can I pass values to the second activity?



Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

I've found the android.app.Application class but am having some troubles getting it to work

~I'm currently getting a classCastException and I don't understand why

My "Global State" object :




This is how I'm trying to set something :





I'm getting a classCast exception on the GlobalState gs = (GlobalState) getApplication();

Any ideas?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Post the relevant part of the AndroidManifest.xml file where you to tell Android to use the GlobalState class. Seeing the actual exception (full stack trace) would also help.
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Hi,

I've been looking at some tutorials, and they mention to include the "global state" class in the manifest file

I've tried their suggestion of including this, but if I put in an application tag, the manifest file won't be valid, as I already have one application set of tags

This is my manifest


Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
According to the page you linked to, registering a different Application class does not involve adding another <application> tag, but adding an "android:name" attribute to the <application> tag that's already there.
Piyush Patel
Ranch Hand

Joined: Feb 24, 2009
Posts: 127

Hi,James

I faced same situation !
in my case i created Static List<Pojo.Class> myList in Activity #1. &added pojo to List by myList.add(pojoObj);
then retried the Pojos in Activity #2 using Activity1.myList Object ;

Done ! i don't know if this is Optimal solution to the problem !!
neways hope this will help you.

Best Regards,
piyushnp



[My Blog] [ Follow @Twitter] | Innovations never goes out of Style...
James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

Cheers guys, I figured it out.

Basically I needed to modify the existing application tag, and to add



I was trying is as ".GlobalState", didn't realise it needed to be the fully qualified name
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass POJOs / data / values between activities?
 
Similar Threads
Activity diagram problem
How to pass data between active's
Tabbed Activity
Need list of movies that will hold the nerves
design alternative