tags:

views:

73

answers:

2

Hi,

i have two applications which i want them to share the same arraylist.

how could i achive something like that? is there anything in Android for sharing such a prefrenceses?

thanks,

A: 

You can implement your own Contentprovider, see http://developer.android.com/reference/android/content/ContentProvider.html

Mathias Lin
All i use is one arraylist? will it be worth to use this mechanisem for such a case?
Moshik
If the values in the array list change often during the app runtime, it's probably the cleanest approach. Afaik a 'shared preferences' approach would only work for application components running in the same context. But with two apps you would have two different application contexts.If the array list values don't change often during the app runtime, you can also store the array list values in a DB or file and read it from there.
Mathias Lin
I used to use Content provider when i deal with databases.. but here i got no database, no tables.. all i need is a global access (read/write) to an arraylist, how could I implement it via content provider?
Moshik
You don't have to use a DB to store the data in the content provider. You can fill the values in app1 and read them out in app2. You just override the query, update, delete methods with your own logic, which doesn't access a database but store the data somewhere non-persistent. I use this approach for example for a custom search provider, where I load up the search/word index on app startup and hold it in a simple bean together with a little bit of logic.
Mathias Lin
Take a look at http://pastebin.com/7i3J2vyZ, I posted the class for my search provider and search index (that would in your case hold the array list).
Mathias Lin
thanks for your help.
Moshik
A: 

When you pass between activities you can send info

Bundle bundle = new Bundle();
bundle.putStringArrayList("ArrayPics",myArrayofPics);         
Intent myIntent= new Intent(ActivityA.this, ActivityB.class);
myIntent.putExtras(bundle);
startActivity(myIntent);    

so your Activity B can receive the ArrayList

you can save data in Shared Preferences too and read in every Activity of your app

Shared Preferences

Jorgesys