Inter Application Communication in Android

2019-05-21 14:25发布

问题:

I have an activity in one application that calls the activity of another application. How can be done with intent or any other way. For example in single application, we can do it like:

Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value is sent by FirstActivity ");

回答1:

Declare android action for the Second Activity and call the Second Activity from First Activity through the Action name. For more info see the below example:

Declared Second Activity in AndroidManifest.xml as

<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="com.sample.action.MY_CUSTOM_ACTION"/>
</intent-filter>
</activity>

Then install the second app first and call the SecondActivity as below:

Intent i = new Intent("com.sample.action.MY_CUSTOM_ACTION");
i.putExtra("mystring","Sample Text");//optional.
startActivity(i);


回答2:

You can use Intent.setComponent