Android Open Handset Developers Community

 
Guest Announcements

:arrow: Welcome: you are not yet registered; you can register here.
:arrow: A new forum on the new HTC Magic is available here.

It is currently Fri Sep 10, 2010 9:52 pm

All times are UTC


 Topics   Replies   Views   Last post 
No new posts ON SALE APPLE IPAD 64GB...$350,Samsung I8000 Omnia II...$200

by HAJJA on Thu Sep 09, 2010 10:21 am in News & Announcements

0

7

Thu Sep 09, 2010 10:21 am

HAJJA

No new posts FOR SALE Nokia 8800 Sapphire Arte..$200,HTC Touch 2...$180

by HAJJA on Thu Sep 09, 2010 10:20 am in News & Announcements

0

7

Thu Sep 09, 2010 10:20 am

HAJJA

No new posts Andreana Haley to receive grant from the American

by puni on Thu Sep 09, 2010 10:07 am in News & Announcements

0

7

Thu Sep 09, 2010 10:07 am

puni

No new posts texas university tx, austin in texas tx university

by puni on Thu Sep 09, 2010 10:07 am in News & Announcements

1

9

Thu Sep 09, 2010 10:07 am

puni

No new posts LG BL40 Chocolate@230USD,BlackBerry Torch 9800@340usd

by bazar01 on Tue Sep 07, 2010 9:09 am in News & Announcements

0

8

Tue Sep 07, 2010 9:09 am

bazar01




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How can MapActivity obtain data
PostPosted: Wed Apr 15, 2009 11:46 am 
Offline

Joined: Wed Apr 15, 2009 11:30 am
Posts: 3
Hi guy,
I'm Michel and i m doing a university project with Android but i'have some problem....
I'am use a TabHost with 2 tab.
The first tab is a class view with a textArea where the user can add city and when click OK the application put that in a array.
The second class is mapActivity I launch that with a intent like this:
Intent startMap = new Intent(this, MyMapView.class);

mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(new Intent(this, MyMapView.class)));

ANd works i can see the map...But How can this activity obtain data from the first class? i want see the array!!!
Any suggestion?

thanks.
ps: sorry for my English!


Top
 Profile  
 
 Post subject: Re: How can MapActivity obtain data
PostPosted: Thu Apr 16, 2009 5:07 pm 
Offline

Joined: Thu Dec 27, 2007 2:51 pm
Posts: 41
Hi Michel,
you can use the two Activityclass 's methods getExtras() and putExtras() pass data between activities by relying on android.os.Bundle

Hope this helps.

Verix


Top
 Profile  
 
 Post subject: Re: How can MapActivity obtain data
PostPosted: Thu Apr 16, 2009 6:25 pm 
Offline

Joined: Wed Apr 15, 2009 11:30 am
Posts: 3
thanks,
I know this, in fact i launch intent with startActivityForResult()
But with getExtras() and putExtras() you can Pass only primitive..
Why not Object???

bye!
Michel


Top
 Profile  
 
 Post subject: Re: How can MapActivity obtain data
PostPosted: Fri Apr 17, 2009 9:12 am 
Offline

Joined: Thu Dec 27, 2007 2:51 pm
Posts: 41
Michel,
you're right: getExtras() and putExtras() are not suitable for user defined objects; for this case, the suggested approaches (ref. ***URLs are hidden from guests, please register and login to view the hyperlink***) are:

Quote:
How do I pass data between Activities/Services within a single application?
It depends on the type of data that you want to share:

Primitive Data Types
To share primitive data between Activities/Services in an application, use Intent.putExtras(). For passing primitive data that needs to persist use the Preferences storage mechanism.

Non-Persistent Objects
For sharing complex non-persistent user-defined objects for short duration, the following approaches are recommended:

The android.app.Application class
The android.app.Application is a base class for those who need to maintain global application state. It can be accessed via getApplication() from any Activity or Service. It has a couple of life-cycle methods and will be instantiated by Android automatically if your register it in AndroidManifest.xml.

A public static field/method
An alternate way to make data accessible across Activities/Services is to use public static fields and/or methods. You can access these static fields from any other class in your application. To share an object, the activity which creates your object sets a static field to point to this object and any other activity that wants to use this object just accesses this static field.

A HashMap of WeakReferences to Objects
You can also use a HashMap of WeakReferences to Objects with Long keys. When an activity wants to pass an object to another activity, it simply puts the object in the map and sends the key (which is a unique Long based on a counter or time stamp) to the recipient activity via intent extras. The recipient activity retrieves the object using this key.

A Singleton class
There are advantages to using a static Singleton, such as you can refer to them without casting getApplication() to an application-specific class, or going to the trouble of hanging an interface on all your Application subclasses so that your various modules can refer to that interface instead.

But, the life cycle of a static is not well under your control; so to abide by the life-cycle model, the application class should initiate and tear down these static objects in the onCreate() and onTerminate() methods of the Application Class


It looks to me that in most cases the approach to use public static fields and/or methods can solve the issue; if not, you have to face the more complicated way of saving the object using a HashMap (good luck.. :mrgreen: )


Top
 Profile  
 
 Post subject: Re: How can MapActivity obtain data
PostPosted: Fri Apr 17, 2009 9:43 am 
Offline

Joined: Wed Apr 15, 2009 11:30 am
Posts: 3
MMMM

yes, i thinks too thet to use static fields and methods is right choose...
But i want see HashMap too maybe is interessant!

thank you very much!
You solve my problem
Michel


Top
 Profile  
 
 Post subject: Re: How can MapActivity obtain data
PostPosted: Fri Apr 17, 2009 10:05 am 
Offline

Joined: Thu Dec 27, 2007 2:51 pm
Posts: 41
Michel wrote:
thank you very much!
You solve my problem

You are welcome ;)

I never tried to use HashMap, but if you succeeded on using it, it will be interesting to know the reults: looking forward to reading you on this issue


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

This site is not affiliated with nor endorsed by the Open Handset Alliance.
All trademarks and logos used in this site are of properties of their respective owners.