【发布时间】:2015-05-29 06:41:32
【问题描述】:
我有 2 个应用程序,A 和 B。
在应用程序A 中,我想调用应用程序B 并从应用程序B 获取结果。我试试这个代码:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.app.B");
startActivityForResult(launchIntent, CODE);
但在我调用该代码后,onActivityResult() 方法立即调用并给出结果RESULT_CANCELLED。
应用 B 清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.B">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".TestActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
App B 测试活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
if (getCallingActivity() == null) {
startActivity(new Intent(this, MainActivity.class));
finish();
} else {
Intent returnIntent = new Intent();
setResult(RESULT_OK, returnIntent);
finish();
}
}
【问题讨论】:
标签: android