1. 程式人生 > >android-在程式碼中實現按下Home鍵的效果

android-在程式碼中實現按下Home鍵的效果

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);