简单说一下这种
主框架(A)与被调用者(B)之间通过隐式的Intent来调用,并将数据使用putExtra() 方法传递。
1) B需要在AndroidManifest.xml 里为允许A调用的Activity配置类似如下代码:
<activityname="xxxx"
...>
<intent-filter>
<actionandroid:name="here is your action name" />
<categoryandroid:name="android.intent.category.DEFAULT" />
......
</intent-filter>
</activity>
2) A通过B配置的action name调用 startActivityForResult 来启动B的activity
3) B处理完成后,调用setResult(resultCode,data)
action的name,以及edtra的key需要双方协商好
App 间数据传递
1、Activity 调用时采用 putExtra() 以及 setResult(resultCode,data)传递数据。
2、广播
3、主框架对外提供 ContentProvider。
关键代码:
调用端:
Intent intent = new Intent(com.cn.test.mainActivity);
Bundle bundle = new Bundle();
bundle.putString("参数1",参数1);
bundle.putString("参数2",参数2);
intent.putExtras(bundle);
startActivity(intent);
被调用端:
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
参数= bundle.getString("参数");