I have two application , com.appone.one
and com.apptwo.two
.
I want transfer data from appone
to apptwo
,I want when a data transferred to apptwo
, apptwo
opens or if open only come up(onResume) and show that data.
I wrote this code:
com.appone.one:
Intent i = new Intent(Intent.ACTION_DATE_CHANGED);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.apptwo.two");
i.putExtra("MessageText",""+Connect.MessageArrive.toString());
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
com.apptwo.two:
@Override
public void onResume() {
super.onResume();
String name=getIntent().getStringExtra("MessageText");
Toast.makeText(getApplicationContext(),String.valueOf(name), Toast.LENGTH_LONG).show();
}
I want only write this line :
String name=getIntent().getStringExtra("MessageText");
in OnResume
because I don't want apptwpo load again,If I write this line in onCreate
, my code works fine. but I want that in onResume
.
Now apptwo
returns null :(
what should I do? thanks in advance
You can use Content Providers for data sharing between your apps. You can learn more about Content Providers from the link below.
http://developer.android.com/guide/topics/providers/content-providers.html
Note: If i'm not wrong to pass data with content providers between your apps, you need to sign your apps with same keystore.
You can also use Intents to pass data to your application. You can check it from below.
http://developer.android.com/training/sharing/send.html
It's not a good practice but you can use shared preferences.
SharedPreferences preferences = getSharedPreferences(PREF_NAME, MODE_WORLD_READABLE);