activity被回收的状态和信息保存和恢复过程

    xiaoxiao2021-04-19  232

    public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { //判断是否有以前的保存状态信息 savedInstanceState.get("Key"); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub //可能被回收内存前保存状态和信息, Bundle data = new Bundle(); data.putString("key", "last words before be kill"); outState.putAll(data); super.onSaveInstanceState(outState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { // TODO Auto-generated method stub if (savedInstanceState != null) { //判断是否有以前的保存状态信息 savedInstanceState.get("Key"); } super.onRestoreInstanceState(savedInstanceState); } }
    转载请注明原文地址: https://ju.6miu.com/read-676258.html

    最新回复(0)