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

Android Intent啟動別的應用實現(xiàn)方法

 更新時間:2013年04月19日 16:26:10   作者:  
我們知道Intent的應用,可以啟動別一個Activity,那么是否可以啟動別外的一個應用程序呢,答案是可以的

我們知道Intent的應用,可以啟動別一個Activity,那么是否可以啟動別外的一個應用程序呢,答案是可以的。

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

2、新建一個工程用于打開上面的應用,程序界面如下

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));// 第一個參數(shù)為應用程序包名,第二個參數(shù)為程序啟動的Activity

 運行程序,點擊AnotherPro將會打開第一個應用;

 點擊Calendar將會打開系統(tǒng)的日歷應用。

相關文章

最新評論