moveTaskToBack()方法:在activity中调用 moveTaskToBack(boolean nonRoot)方法即可将activity 退到后台。
在activity onCreate函数钟添加moveTaskToBack方法:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.e("====", "onCreate()"); moveTaskToBack(true); }
app运行时的表现如下:
1,第一次点击app图标:
会执行如下流程:
01-18 10:30:40.523 9659 9659 E ==== : onCreate()
01-18 10:30:40.532 9659 9659 E ==== : onStart()
01-18 10:30:40.534 9659 9659 E ==== : onResume()
01-18 10:30:40.550 9659 9659 E ==== : onPause()
01-18 10:30:40.722 9659 9659 E ==== : onStop()
显示效果为闪一下之后看不到界面。
2,
第二次点击demo图标:
01-18 10:31:10.967 9659 9659 E ==== : onRestart()
01-18 10:31:10.971 9659 9659 E ==== : onStart()
01-18 10:31:10.972 9659 9659 E ==== : onResume()
效果为界面显示了出来。
3,关闭app:
01-18 10:38:48.795 9659 9659 E ==== : onPause()
01-18 10:38:48.832 9659 9659 E ==== : onStop()
01-18 10:38:53.027 9659 9659 E ==== : onDestroy()
demo源码地址为:
https://github.com/guanguanboy/android_demos/tree/master/MoveTaskToBackDemo