簡體   English   中英

Android創建啟動器,但無法啟動其他應用

[英]Android creating a launcher but not able to launch other apps

我在android中創建啟動器。 讓我解釋一下情況。

情況1:當我從android studio運行myLauncher應用程序時,它首先作為普通應用程序運行。 然后,我在myLauncher中打開應用程序抽屜,然后單擊圖標以啟動另一個應用程序,它運行正常。 退出應用程序后,我再次回到myLauncher,就像它在android堆棧上一樣。 這是我想要的行為。

情況2:我的應用程序在android上安裝后,按主屏幕按鈕選擇默認啟動器,然后選擇myLauncher作為默認啟動器。 它會打開,然后在myLauncher中打開應用程序抽屜。 單擊任何圖標以啟動另一個應用程序后,它將不起作用。

盡管我在Cordova工作,但是我認為問題並不是Cordova的問題,因為myLauncher未作為啟動程序運行時一切正常。

Intent launchIntent = cordova.getActivity().getApplicationContext().getPackageManager().getLaunchIntentForPackage(args.get(0).toString());
cordova.getActivity().getApplicationContext().startActivity(launchIntent);

案例1的Logcat:

01-10 11:37:57.526  1555  1638 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.android.dialer cmp=com.android.dialer/.DialtactsActivity} from uid 10057 on display 0
01-10 11:37:57.526  1555  1638 W ActivityManager: Activity is launching as a new task, so cancelling activity result.
01-10 11:37:57.536  1555  1638 D         : HostConnection::get() New Host Connection established 0x7f1132abef40, tid 1638
01-10 11:37:57.545  1236  1236 E EGL_emulation: tid 1236: eglCreateSyncKHR(1370): error 0x3004 (EGL_BAD_ATTRIBUTE)
01-10 11:37:57.610  3983  3983 D CordovaInterfaceImpl: Sending activity result to plugin
01-10 11:37:57.612  1555  1638 D gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
01-10 11:37:57.629  3983  4017 W PluginManager: THREAD WARNING: exec() call to Apps.start blocked the main thread for 104ms. Plugin should use CordovaInterface.getThreadPool().
01-10 11:37:58.025  1555  1575 I ActivityManager: Displayed com.android.dialer/.DialtactsActivity: +333ms
01-10 11:37:58.308  3983  3983 I Choreographer: Skipped 30 frames!  The application may be doing too much work on its main thread.
01-10 11:37:58.464  3983  4025 E Surface : getSlotFromBufferLocked: unknown buffer: 0x7f11433b9d90

案例2的Logcat:

01-10 11:34:15.739  1555  1803 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.android.dialer cmp=com.android.dialer/.DialtactsActivity} from uid 10057 on display 0
01-10 11:34:15.739  1555  1803 W ActivityManager: Activity is launching as a new task, so cancelling activity result.
01-10 11:34:15.791  1555  1575 D         : HostConnection::get() New Host Connection established 0x7f1132cba040, tid 1575
01-10 11:34:16.463  1555  1575 D gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
01-10 11:34:16.566  1555  1638 W InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@668d511 attribute=null, token = android.os.BinderProxy@20e786d

我進行了兩項更改, 現在可以使用

在清單中,我在活動中添加了android:launchMode="singleTop"和意圖啟動,並將其放入可運行對象中。

        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Intent launchIntent = cordova.getActivity().getApplicationContext().getPackageManager().getLaunchIntentForPackage(args.get(0).toString());
                    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    cordova.getActivity().getApplicationContext().startActivity(launchIntent);
                } catch (JSONException exp) {
                    Log.e("ERR", "JSON Error");
                } catch (Exception exp) {
                    Log.e("ERR", "Other Error: " + exp.getMessage());
                }

            }

更新:不,這不起作用。 必須混合了apk。 如果我一直快速點擊應用程序圖標,則該應用程序確實會立即打開和關閉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM