简体   繁体   中英

Best practices for sharing data between android apps

I need to share data between two android apps that are on the same phone without using the internet. The data I want to share includes a several key value pairs of different data types. The options I am aware of are:

  1. Using intents - Send and Receive . But the typical examples for intents do not involve these use cases. Intents seems more suited for sharing data of a particular mime type or launch apps (or let users choose from) to handle the data being shared.

  2. Sharing the SharedPreferences . However the MODE_WORLD_READABLE or MODE_WORLD_WRITEABLE flags required for this have been deprecated post API 17.

  3. Broadcast Receivers - But I'm not exactly listening to events. I want to use a request/response cycle.

  4. Content Providers . This is great except for the fact that I need to store the data in a database in the app sharing the data. If I have key, value pairs where the value can be of different data types, this makes the data table a bit cumbersome. Is there a better way to do this with content providers?

Which is the best technique to adopt?

I created a small library that makes it simple to share SharedPreferences from one app to another in a READ ONLY fashion using ContentProvider .

Described it here - https://github.com/ratpik/android-sharedpreferences-api/blob/master/README.md

You can set up Broadcast Reciever on one end to listen for particular intent type. And broadcast intents from first application with data held in extras. You can send whole objects via intent using parcerable approach.

More about parcerable approach can be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM