安卓一個程序調用其他程序的任一界面問題

一般都是系統的通知欄或者推送 需要調起應用中的某一個界面進行交互 比如活動之類的
這邊需求是打開之後可以返回的本應用的主界面
所以根據需求就是1.如何打開 2.多開的問題

        Intent intentMain = new Intent();
            intentMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            ComponentName componentName1 = new ComponentName(packName, startMain);
            intentMain.setComponent(componentName1);

            Intent intentWeb = new Intent();
            ComponentName componentName = new ComponentName(packName, startActivityName);
            intentWeb.setComponent(componentName);
            intentWeb.setAction(Intent.ACTION_VIEW);
            intentWeb.putExtra("startName",startName);
            Intent[] intents={intentMain,intentWeb};
            context.startActivities(intents);

以上的代碼 是需要其他想打開你app的應用或者系統需要編寫的代碼
你只需要提供packName ,startMain startActivityName 這些參數
分別是APP 包名 appMain類的全路徑名字 還有 指定界面的全路徑名字
這裏需要注意一個關鍵環節 就是你的app main 和想打開的指定界面都需要
在清單文件中吧入口設置爲true

<activity
            android:name=".MainActivity"
            android:launchMode="singleTask"
            android:exported="true"
            android:screenOrientation="landscape" />

這樣提供訪問入口 其他程序或者系統纔可以訪問你
如何你想打開的是fragment 那麼就可以利用傳值 來判斷打開的那個fragment 以上

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