activty生命周期的几个方法

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        System.out.println("onCreate 被创建了");
        
        sharedPreferences = getSharedPreferences("xiaoer", 0);
        TextView tv = (TextView) findViewById(R.id.tv);
        String name = sharedPreferences.getString("name", "sb");
        System.out.println(name);
        tv.setText(name);
    }


    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        System.out.println("onStart 被创建了");
    }
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        System.out.println("onResume 被创建了");
    }
    
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        System.out.println("onPause 被创建了");
    }
    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        System.out.println("onStop 被创建了");
    }
   
    
    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        System.out.println("onDestroy 被创建了");
        Editor edit = sharedPreferences.edit();
        edit.putString("name", "xiaoer2");
        edit.commit();
    }
    
    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        super.onRestart();
        System.out.println("onRestart 被创建了");
    }

你可能感兴趣的:(activty生命周期的几个方法)