`
李楚男
  • 浏览: 117856 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

从一个Activity跳转到另一个Acitivty必然要经历的生命周期有哪几个

 
阅读更多
Activity_A代码:
public class Activity_A extends Activity {
private Button button;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        System.out.println("A------------onCreate");
        button = (Button) findViewById(R.id.bt);
        button.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(Activity_A.this, Activity_B.class);
startActivity(i);
}
       
        });
    }

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
        System.out.println("A------------onDestroy");
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
System.out.println("A------------onPause");
}

@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
System.out.println("A------------onRestart");
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
System.out.println("A------------onResume");
}

@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
System.out.println("A------------onStart");
}

@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
System.out.println("A------------onStop");
}
   
   
}

Activity_B:
public class Activity_B extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        System.out.println("B------------onCreate");
    }

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
        System.out.println("B------------onDestroy");
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
System.out.println("B------------onPause");
}

@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
System.out.println("B------------onRestart");
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
System.out.println("B------------onResume");
}

@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
System.out.println("B------------onStart");
}

@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
System.out.println("B------------onStop");
}
   
   
}
当按下跳转按钮:
A:onpause();
B:onCreate();
B:onStart();
B:onResume();
A:onStop();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics