如何启动另一程序的特定activity

2024-12-16 03:09:50
推荐回答(1个)
回答1:

在一个Android应用程序A中调用另一个Android程序B,同时传递数据给B

ComponentName componentName = new ComponentName(
"com.xiaohua.player.activity",
"com.xiaohua.player.activity.PlayerActivity");
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("resUrl", resurl);
bundle.putSerializable("picUrlList", picurllist);
intent.putExtras(bundle);
intent.setComponent(componentName);
startActivity(intent);
注:
com.xiaohua.player.activity:包路径
PlayerActivity:Activity类
resUrl :String类型
picUrlList:数组,也可以是对象
应用程序安装后,按以上方式可进行调用.

接受activity:
public void getParameterByIntent() {
Intent mIntent = this.getIntent();
String resUrl = mIntent.getStringExtra("resUrl");
String[] picUrlList = (String[]) mIntent.getSerializableExtra("picUrlList");
if (null != picUrlList) {
int count = picUrlList.length;
for (int i = 0; i < count; i++) {
Log.e("tag", "picUrlList[" + i + "]" + picUrlList[i]);
}
}
}