初识Activity_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > 初识Activity

初识Activity

 2016/7/15 5:32:51  codemonkey(xsy)  程序员俱乐部  我要评论(0)
  • 摘要:CallbackDescriptiononCreate()Thisisthefirstcallbackandcalledwhentheactivityisfirstcreated.onStart()Thiscallbackiscalledwhentheactivitybecomesvisibletotheuser.onResume()Thisiscalledwhentheuserstartsinteractingwiththeapplication.onPause(
  • 标签:Activity
CallbackDescription onCreate() This is the first callback and called when the activity is first created. onStart() This callback is called when the activity becomes visible to the user. onResume() This is called when the user starts interacting with the application. onPause() The paused activity does not receive user input and cannot execute any code and called when the current activity is being paused and the previous activity is being resumed. onStop() This callback is called when the activity is no longer visible. onDestroy() This callback is called before the activity is destroyed by the system. onRestart() This callback is called when the activity restarts after stopping it.

关键代码如下:

public class MainActivity extends Activity {
private String msg="Android: ";
/**
* Called when the activity is first created.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}

/**
* Called when the activity is about to become visible.
*/
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.d(msg, "The onStart() event");
}

/**
* Called when the activity has become visible.
*/
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.d(msg, "The onResume() event");
}

/**
* Called when another activity is taking focus.
*/
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.d(msg, "The onPause() event");
}

/**
* Called when the activity is no longer visible.
*/
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.d(msg, "The onStop() event");
}

/**
* Called just before the activity is destroyed.
*/
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.d(msg, "The onDestroy() event");
}
}

 

运行截图:

当Activity第一次打开时:

当启动另一个Activity时:

当关闭当前的Activity,返回到先前的Activity时:

当销毁当前Activity时:

 

发表评论
用户名: 匿名