Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass POJOs / data / values between activities?

 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic