Data sharing between two applications

The question:

Recently i had an interview in which the question was asked as “How would you be able to share the data between two installed apps or apk’s?”

I didn’t have any answer for this question. Can anyone help me in determining an way to do so…

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Send data from Application 1 (for ex:Application 1 package name is “com.sharedpref1” ).

SharedPreferences prefs = getSharedPreferences("demopref",
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("demostring", strShareValue);

Receive the data in Application 2( to get data from Shared Preferences in Application 1).

    try {
            con = createPackageContext("com.sharedpref1", 0);//first app package name is "com.sharedpref1"
            SharedPreferences pref = con.getSharedPreferences(
                        "demopref", Context.MODE_PRIVATE);
            String your_data = pref.getString("demostring", "No Value");
    catch (NameNotFoundException e) {
                Log.e("Not data shared", e.toString());

In both application manifest files add same shared user id & label,

 android:sharedUserId="any string" 

both are same… and shared user label must from string.xml

like this example.

<manifest xmlns:android=""
android:sharedUserId="any string" 

Method 2

ContentProviders are a good approach to share data between applications.

Method 3

If you want to share data between applications, make sure you sign with the same key:

Code/data sharing through permissions – The Android system provides
signature-based permissions enforcement, so that an application can
expose functionality to another application that is signed with a
specified certificate. By signing multiple applications with the same
certificate and using signature-based permissions checks, your
applications can share code and data in a secure manner.

This is quoted from: android developer page about signing

If it’s a small amount of data you could send it through an intent.

Method 4

I suspect they were likely looking for Android specific methods such as the content provider answer.

Other alternatives…
Android Specific – Remote services
General – TCP/IP connections
General – Writing to a location on the SD card

Care to hear more about a specific method?

Also stealing this question for an interview today 🙂

Method 5

Content provider is the android component, which has to be used if one application wants to share its data with other application.

Note: Files, SqliteDatabases, Sharedpreference files created by an application is private to only that application. Other application can’t directly access it. If programmer exposes database by using content provider, then only that data is accessible to other applications. To communicate with content provider use content resolver.

Method 6

My requirement was to send a simple string from one app to another and get a string back. Like “user id” from App1 to App2 and get “username” back to App1. I was able to achieve this using implicit intent and startActivityForResult. If anyone is looking for the full process I posted my answer here How to send data between one application to other application in android?.

App1 >

        //Need to register your intent filter in App2 in manifest file with same action.
        intent.setAction("com.example.sender.login"); // <packagename.login>
        startActivityForResult(intent, REQUEST_CODE);

        onActivityResult(...) {
           // Handle received data from App2 here

I had two activity in App2 ie. MainActivity and LoginActivity.

App2 > AndroidManifest.xml

        <!--The action has to be same as App1-->
        <action android:name="com.example.sender.login" />

App2 >

override fun onResume() {
    // Handle data from App1 here

fun onClickBack(view: View) {
    val intent = intent
    // Set data in bundle here for App1
    setResult(Activity.RESULT_OK, intent)

Method 7

  1. using implicit intent and startActivityForResult.
  2. Using Content provider

eg of content Providor:

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment