aspose file tools*
The moose likes Android and the fly likes what is the best way to transfer data via activities in android Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "what is the best way to transfer data via activities in android" Watch "what is the best way to transfer data via activities in android" New topic
Author

what is the best way to transfer data via activities in android

sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
I need to transfer data(set of ArrayLists) via activities.I need to do this without database.what is the besatway to do this?
1)Global variable
2)Use Super class
3)Shared variable
4)any other way

please help?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

It depends on the data, the scope of the data, and the purpose of the data, and the relationship of the Activities. Most of the options you listed are the wrong ways in general, though possibly right in limited contexts. Other options include using Intent Extras and Bundles if one Activity creates the data follows a flow similar to the Activity navigation, Services if the data is cumulative, modifiable and long standing, or Application scope if the data is static and global.


Steve
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 328
    
    6

Do you want to pass data between Activities, or share data among Activities? What does the data look like? ArrayLists of what?
Steve Myers
Ranch Hand

Joined: Dec 08, 2012
Posts: 47
sam liyanage wrote:I need to transfer data(set of ArrayLists) via activities.I need to do this without database.what is the besatway to do this?
1)Global variable
2)Use Super class
3)Shared variable
4)any other way

please help?


Besides what others have mentioned, making the objects in the list Serializable and writing/reading a file can be effective. This is effective when you need to persist the data even if the app is exited.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
Steve
Most of the options you listed are the wrong ways in general

why you say like that?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
You should answer Ron's question and provide more details, otherwise people are just guessing what exactly you're trying to do, and that's not an effective way to help.


Ping & DNS - my free Android networking tools app
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
i have several activities.I need to share my data(Set of ArralyLists) in all that activities.what is the best method except database?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
"best" in what sense?
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
performance,security...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
Performance most likely doesn't matter; if you think it might you should tell us what you intend to do. Since you haven't provided ans details it's possible we're misunderstanding what you want to do.

Security is too big a field to put a single metric on for each approach - you would need to tell us what attacks you want to guard against.

As to what "..." might mean, I don't think I need to spell out that we can't read your mind.
Ron McLeod
Ranch Hand

Joined: Feb 12, 2013
Posts: 328
    
    6

If best also equals simple, the you could just subclass Application and use it to store your shared information. You could also use a Singleton. This should be a plus for your performance requirement as well (although it is unlikely performance would be an issue anyway).

The obvious downside is that there is no persistence -- if/when the application get destroyed, the data will be lost. Depending on your security requirements, that may actually be an upside.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
Hi Ron McLeod

Could you please explain how to use Singleton in here?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
I used to use Application subclasses (which are Singletons by nature) for keeping shared data, but have recently moved towards the https://github.com/greenrobot/EventBus/ library - a very handy and versatile way to distribute data across the various components of an application. It obviates the need to reference an Application class, and nicely decouples source and destination of shared data.
sam liya
Ranch Hand

Joined: Nov 25, 2008
Posts: 1204
Thanks Ulf.
 
 
subject: what is the best way to transfer data via activities in android