1

I have two application..

One for main application.. another one for title changer..

If I enter the title in one application it affected in another application..

What I am tried,

I already done by store database in SD card..And refer title using DBHelper.

My problem,

But now my database moved into main application.. so I cannot refer database from title changer application.

My question,

Without database creation can I pass data between two application..like intent or shared preferences?

Note: both application stored in same device..

Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159

3 Answers3

1

You have multiple ways to achieve this.

  1. Usage of Content Providers
  2. Shared Preferences with MODE_WORLD_WRITEABLE
  3. Whenever content is changed in one app, send a broadcast intent which can be read by the other app using a receiver.
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
1

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

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

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" 
 android:sharedUserLabel="@string/any_string"

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

like this example.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxxx"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="any string" 
android:sharedUserLabel="@string/any_string">
Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159
-1

You can use intents. You can send an intent from an Activity to an Activity in another Application and pass data as "Extras" in the sending intent. You have to create a new activity that uses a custom action with the default category. Chech Android Intents - Android Developers

  • An Intent is a messaging object you can use to request an action from another app component (Activities,Services,Recievers...) not only for the same application. – Hadi Chahine --Droido-- Feb 14 '15 at 09:28