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();
分享到:
相关推荐
而`Fragment`则是在`Activity`内部的一个可重用的组件,它可以有自己的视图层次结构,并且可以在多个`Activity`之间进行复用。 ### Activity详解 `Activity`是Android应用的核心组成部分,代表了用户可见的屏幕界面...
参考答案:一般情况下,Activity常见的生命周期只有以下7个 onCreate() :表示正在创建Activity**,常用来初始化work**,比如调用setContentView加载界面布局资源,初始化Activity需要的数据等。 onRestart() :表示...
AndroidKeyboardWatcher Android的软件键盘打开/...用法确保在AndroidManifest.xml的Acitivty配置中使用AdjustResize windowSoftInputMode: 在您的Activity.onCreate()方法中绑定KeyboardWatcher。 为了防止内存泄漏
Make sure that you use adjustResize windowSoftInputMode in your Acitivty configuration in AndroidManifest.xml: Bind KeyboardWatcher in your Activity.onCreate() method. To prevent memory leaks make ...
Android SDK不提供直接方法来从软件键盘跟踪打开/关闭事件。 这个小图书馆为您完成。 用法 确保在AndroidManifest.xml的Acitivty配置中使用adjustResize windowSoftInputMode: < activity xss=removed xss=...
KSI-伴侣通过为我所在的游戏社区创建配套应用程序来学习 Xamarin。 Some notable features on the app:- An... An acitivty showing the "Hall of Fame" of the community- An activity dedicated to helpful and relev