i've tried to sending data between App1 to App2 via Intent in Android
i used this code but i couldn't resolve my problem.
App1 MainActivity :
Intent i2 = new Intent("com.appstore.MainActivity");
i2.setPackage("com.appstore");//the destination packageName
i2.putExtra("Id", "100");
startActivity(i2);
App2 MainActivity :
Bundle data = getIntent().getExtras;
if(data!=null){
String myString = b.getString("Id");
}
Manfiest App2 MainActivity:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
Content providers:
Content providers are the standard interface that connects data in one process with code running in another process.
See Android Docs.
Content provider working demo here.
Final code:
App 1 :
App 2:
Manifest :
MainActivity :
When you do this:
you are calling the single-argument constructor of
Intent
. In this constructor, the argument is interpreted as theIntent
ACTION. You then set the package name in theIntent
.When you call
startActivity()
with thisIntent
, Android will look for anActivity
that contains an<intent-filter>
with the specified ACTION. There are no installed applications that have anActivity
defined like this in the manifest:So Android will not be able to find and launch the
Activity
that you want.As you want to specify explicitly the component that you want to use, instead of using the 1-argument
Intent
constructor, you should do this instead:Using
setClassName()
you provide the package name and the class name of the component that you want to launch.Using
Bundle.putSerializable(Key,Object);
andBundle.putParcelable(Key, Object);
the former object must implementSerializable
, and the latter object must implementParcelable
.