• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ron McLeod
Bartender
Pie
Posts: 963
59
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve
Most of the options you listed are the wrong ways in general

why you say like that?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"best" in what sense?
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
performance,security...
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 963
59
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron McLeod

Could you please explain how to use Singleton in here?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic