一個應用程式啟動另一個應用程式的Activity

來源:互聯網
上載者:User

第一種(我自己寫的) :之前在網上看來一些,很多不是我要的可以啟動另外一個應用程式的主Activity.

//這些代碼是啟動另外的一個應用程式的主Activity,當然也可以啟動任意一個Activity
ComponentName componetName = new ComponentName(
//這個是另外一個應用程式的包名
"com.poynt.weibo",
//這個參數是要啟動的Activity
"com.poynt.weibo.ui.IndexActivity");

try {
Intent intent = new Intent();
intent.setComponent(componetName);
startActivity(intent);
} catch (Exception e) {
// Toast.makeText(getApplicationContext(), "可以在這裡提示使用者沒有找到應用程式,或者是做其他的操作!", 0).show();

}
複製代碼


第二種

:這裡是啟動另外一個程式的Activity之後,並把參數傳過去!
在一個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);
}
}
}

來自:http://hi.baidu.com/huaxinchang/blog/item/5fa81903474097f409fa9305.html
複製代碼

 

第三種:在一個apk中調用另外一個apk中的activity

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.