Android Home鍵 點捷徑功能表應用重啟問題【完美解決】,androidhome

來源:互聯網
上載者:User

Android Home鍵 點捷徑功能表應用重啟問題【完美解決】,androidhome

前言

1、這個問題困擾我n久n久

2、網上出現很多解決方案,大多是設定lanchModel 雖然這樣能解決一些問題,但是不能完全解決,且與我的情況也不相符


解決方案:

方案一:

    1、如果你的程式有管理activity的棧,可以在啟動LogoActivity的onCreate中判斷這個棧是存在其他的activity 如果有 本身直接 finish + return 。這樣是ok,但是總感覺有種不靠譜的感覺。


方案二:

   2、 無意中發現原來是建立的捷徑的問題,捷徑的flag或者intent的建立方式導致重啟。

        關於如何建立捷徑 這裡省略

    看代碼

   public void addShortCut(){
        
        Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        // 設定屬性
    ...

 ...

 ...

        //點擊捷徑的操作

        這裡的intent 必須要新建立的,不能使用 getintent 或者getPackmager.getLaunchIntentFor...等方式建立,如果這樣建立導致 setflag無效
        Intent intent = new Intent();

         intent.setComponent(getComponentName());

         intent.setAction(intent.ACTION_MAIN);

         intent.addCategory(Intent.CATEGORY_LAUNCHER);

       //要添加這句話

        intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED| Intent.FLAG_ACTIVITY_NEW_TASK);
       
        // 設定啟動程式
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
        //廣播通知案頭去建立
        this.sendBroadcast(shortcut);
    }

      


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.