在代码中实现按下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); 

你可能感兴趣的:(android,action)