欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android Intent啟動(dòng)別的應(yīng)用實(shí)現(xiàn)方法

 更新時(shí)間:2013年04月19日 16:26:10   作者:  
我們知道Intent的應(yīng)用,可以啟動(dòng)別一個(gè)Activity,那么是否可以啟動(dòng)別外的一個(gè)應(yīng)用程序呢,答案是可以的

我們知道Intent的應(yīng)用,可以啟動(dòng)別一個(gè)Activity,那么是否可以啟動(dòng)別外的一個(gè)應(yīng)用程序呢,答案是可以的。

1、首先我們新建一個(gè)Android應(yīng)用,名為AnotherPro,此應(yīng)用什么內(nèi)容都沒有,用于被另外一個(gè)程序打開。

2、新建一個(gè)工程用于打開上面的應(yīng)用,程序界面如下

3、修改程序代碼,在onCreate中添加如下代碼

anotherPro = (Button) findViewById(R.id.startAnotherPro);calendar = (Button) findViewById(R.id.startCalendar);anotherPro.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();intent.setComponent(new ComponentName("com.anotherpro", "com.anotherpro.MainActivity"));startActivity(intent);}});calendar.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));startActivity(intent);}});
Intent.setComponent(new ComponentName(packageName, mainActivityName));// 第一個(gè)參數(shù)為應(yīng)用程序包名,第二個(gè)參數(shù)為程序啟動(dòng)的Activity

 運(yùn)行程序,點(diǎn)擊AnotherPro將會(huì)打開第一個(gè)應(yīng)用;

 點(diǎn)擊Calendar將會(huì)打開系統(tǒng)的日歷應(yīng)用。

相關(guān)文章

最新評(píng)論