第一种方法

Intent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_HOME);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);startActivity(intent);

第二种方法

此方法其实不是主要是屏蔽Keycode_Back,让它不结束(finish())Activity,直接显示HOME界面。

PackageManager pm = getPackageManager();                                ResolveInfo homeInfo = pm.resolveActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0);

public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {ActivityInfo ai = homeInfo.activityInfo;Intent startIntent = new Intent(Intent.ACTION_MAIN);startIntent.addCategory(Intent.CATEGORY_LAUNCHER);startIntent.setComponent(new ComponentName(ai.packageName,ai.name));startActivitySafely(startIntent);return true;} elsereturn super.onKeyDown(keyCode, event);}

void startActivitySafely(Intent intent) {intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);try {startActivity(intent);} catch (ActivityNotFoundException e) {Toast.makeText(this, R.string.unabletoopensoftware,Toast.LENGTH_SHORT).show();} catch (SecurityException e) {Toast.makeText(this, R.string.unabletoopensoftware,Toast.LENGTH_SHORT).show();Log.e(TAG,"Launcher does not have the permission to launch "+ intent+ ". Make sure to create a MAIN intent-filter for the corresponding activity "+ "or use the exported attribute for this activity.",e);}}

更多相关文章

  1. Android图形显示系统——上层显示1:界面绘制大纲
  2. Android(安卓)如何屏蔽Home键
  3. Android(安卓)平台的 Google Reader 更新 UI 并支持 Honeycomb
  4. Android连载之:第三章第二节:Android用户界面
  5. Android做的第一个小程序
  6. Android(安卓)Studio-手把手教你做启动界面开发
  7. Android菜鸟的成长笔记(3)——给QQ登录界面说So Easy
  8. Android(安卓)如何在自定义界面上启用输入法 (How to enable inp
  9. android 仿ios数字密码解锁界面

随机推荐

  1. android中读写文件
  2. Android(安卓)学习资料(一)
  3. Android动态改变高度以及计算长度的EditT
  4. Android中widget组件的开发流程
  5. Android(安卓)Activity之间切换出现短暂
  6. Android(安卓)FrameWork——Touch事件派
  7. android adb 命令
  8. 装饰者模式及其应用
  9. Android(安卓)UI开发第十二篇——动画效
  10. Android(安卓)链式调用(方法链)