【android】 調用別的應用的activity

第一種:ComponentName()

使用ComponentName()可以跳轉到任何一個activity,不論是不是main activity。也不必寫修改被調用的apk的AndroidManifest.xml任何內容,如下:

ComponentName componetName = new ComponentName(
                 //這個是另外一個應用程序的包名 
                "com.hooy.apk2",
                //這個參數是要啓動的Activity 
                "com.hooy.apk2.Pay_Activity"); 
//        Intent intent= new Intent("chroya.foo");
        Intent intent= new Intent();
        //我們給他添加一個參數表示從apk1傳過去的
        Bundle bundle = new Bundle();
        bundle.putString("arge1", "這是跳轉過來的!來自apk1");
        intent.putExtras(bundle);
        intent.setComponent(componetName);
        startActivity(intent);

第二種方法Intent+AndroidManifest.xml

顧名思義,此方法是用Intent和修改AndroidManifest.xml達成的。
<intent-filter>   
        <action android:name="com.foo"/>   
        <category android:name="android.intent.category.DEFAULT"/>   
</intent-filter> 

Intent intent = new Intent("com.foo");   
startActivity(intent);    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章