【发布时间】:2014-02-21 04:25:26
【问题描述】:
我安装了两个应用程序 app1 和 app2。 我想从 app1 启动 app2 的活动。然后使用来自 app2 的一些数据返回 app1 上的活动。但我可以返回 app1 ,但无法获取数据。
来自 app1:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, sampleText);
intent.setType("text/plain");
intent.setComponent(new ComponentName("com.example.app2","com.example.app2.MainActivity"));
startActivity(intent);
来自 app2:
Intent goBack = new Intent();
goBack.putExtra("result","asdaf");
setResult(RESULT_OK, goBack);
finish();
app1 的清单:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
app2 的清单:
<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="text/plain" />
</intent-filter>
我在 app1 中的功能没有受到影响。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if(resultCode == RESULT_OK){
String result=data.getStringExtra("result");
TextView tv = (TextView)findViewById(R.id.textView3);
tv.setText(result);
}
if (resultCode == RESULT_CANCELED) {
//Write your code if there's no result
}
}
}
我在这里缺少什么?是否需要为此进行任何设置?
【问题讨论】:
标签: java android android-intent android-manifest