簡單說一下這種
主框架(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("參數");