Background running of android implemented programs
/*** Rewrite the event listening of the Return key so that the back key function is similar to the home key, so that the Acitivty will not be destroyed by the system when it is returned to the background */@ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {PackageManager pm = getPackageManager (); ResolveInfo homeInfo = pm. resolveActivity (new Intent (Intent. ACTION_MAIN ). addCategory (Intent. CATEGORY_HOME), 0); 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);} private void startActivitySafely (Intent intent) {intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); try {startActivity (intent);} catch (ActivityNotFoundException e) {Toast. makeText (this, "null", Toast. LENGTH_SHORT ). show ();} catch (SecurityException e) {Toast. makeText (this, "null", Toast. LENGTH_SHORT ). show ();}}