我有两个应用程序A和B.
申请A
以下代码我从应用程序活动中启动B Application for get Result ..
String packageName = "com.cm.applicationb";
PackageManager manager = context.getPackageManager();
Intent i = manager.getLaunchIntentForPackage(packageName);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.putExtra("grand_total", "2500");
i.setAction(packageName);
startActivityForResult(i, REQUEST_DATA);
从应用程序A调用onActivityResutl
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==REQUEST_DATA)
if (resultCode == Activity.RESULT_OK) {
me=data.getStringExtra("Obj");
}
Toast.makeText(getApplicationContext(),me,Toast.LENGTH_LONG).show();
}
B应用程序setResult数据
Intent i=new Intent();
i.putExtra("Obj", "object");
setResult(Activity.RESULT_OK, i);
finish();
从onActivityResult开始重新调整null数据和结果代码。我们怎么解决呢?从另一个应用程序setREsult获取数据onAcitivityResult是不可能的。有人请帮助我。非常感谢你。
答案 0 :(得分:0)
删除finish()
并在B
@Override
public void onBackPressed() {
Intent data = new Intent();
Bundle bundle = new Bundle();
bundle.putString("Obj", "Obj_Data");
data.putExtras(bundle);
setResult(Activity.RESULT_OK, data);
super.onBackPressed(); // this calls finish(); internally.
}
答案 1 :(得分:0)
只需将此行添加到manifest.xml
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
有关更多详细信息,请选中this links,该说明解释了如何从其他应用程序接收数据