2025-05-23

Android設備在按下Home鍵會自動切換回桌面,其實實現的方法很簡單,由於Launcher捕獲瞭Home鍵的按下action,我們直接發送個Intent給Launcher即可,代碼如下:

 

Intent intent= new Intent(Intent.ACTION_MAIN); 

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //如果是服務裡調用,必須加入new task標識   

intent.addCategory(Intent.CATEGORY_HOME);

startActivity(intent);   

摘自  Central-Perk的專欄
 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *