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 Mon Feb 06, 2012 6:00 pm

All times are UTC


 Topics   Replies   Views   Last post 
No new posts Rip Blu-ray video to Blackberry Playbook

by alex6699 on Fri Nov 26, 2010 2:56 am in Relaxing Lounge

0

213

Fri Nov 26, 2010 2:56 am

alex6699

No new posts A calls Blocker Software for Windows Mobile

by tingelsky on Tue Nov 16, 2010 7:08 am in Relaxing Lounge

0

137

Tue Nov 16, 2010 7:08 am

tingelsky

No new posts android ksoap2 Caused by: java.lang.RuntimeException: Cannot

by mindus on Thu Sep 30, 2010 6:07 am in Beginner level ANDROID developing issues

0

187

Thu Sep 30, 2010 6:07 am

mindus

No new posts Create a pdf file dynamically

by mindus on Wed Sep 22, 2010 8:47 am in Beginner level ANDROID developing issues

0

104

Wed Sep 22, 2010 8:47 am

mindus

No new posts How can I backup my mobile contacts to my pc?

by weibin.li on Tue Aug 10, 2010 7:28 am in Relaxing Lounge

1

151

Tue Aug 10, 2010 7:28 am

weibin.li




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.