将android应用后台运行
Intent i= new Intent(Intent.ACTION_MAIN); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //如果是服务里调用,必须加入new task标识 i.addCategory(Intent.CATEGORY_HOME); startActivity(i);
?
?
public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){ if((System.currentTimeMillis()-exitTime) > 2000){ Toast.makeText(getApplicationContext(), R.string.exit_title, Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else { try{ Intent i= new Intent(Intent.ACTION_MAIN); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //如果是服务里调用,必须加入new task标识 i.addCategory(Intent.CATEGORY_HOME); startActivity(i); }catch(Exception e){ } //System.exit(0); } return true; } return super.onKeyDown(keyCode, event);}
?