先说一下 activity stack 栈,系统管理activity,新启一个activity会在stack上加一个,压在以前的之上,退出当前的,以前的才会显示出来
Activity 生命周期: 七个方法
public class Activity extends ApplicationContext {
protected void onCreate(Bundle savedInstanceState); 生
protected void onStart(); 可见
protected void onRestart(); 重新可见
protected void onResume(); 恢复
protected void onPause(); 暂停
protected void onStop(); 停止
protected void onDestroy(); 死
}
activity生命的四种状态: activity的回收由android系统来做
1. If an activity in the foreground of the screen (at the top of the stack), it is active or running.
如果activity在前台运行,并拥有焦点,那么他是active或running
2. If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.
失去焦点,但activity仍然是可见的,例如有一个弹出框,他会变成paused,这时他仍然是一个活的activity,保持所有信息并被window manager管理。在系统内存极度缺少时会被回收。
3. If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.
当activity完全被另一个activity覆盖,完全不可见时,他是stopped。仍会保持状态和成员信息,但是很可能会被系统回收
4. If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.
如果一个activity是暂停或停止的,系统可以从内存中删掉此activity
Logcat:打印日志信息的
用法 Log.i() 打印info信息
Log.d() 打印debug信息
Log.w() 打印警告信息
Log.v() 打印verbose信息 ,详细的,啰嗦的
Log.e(); 打印error信息
Toast 吐司 提示信息的用法
Toast的特点:不获得焦点,所以不影响不打断用户的操作。例如用在音量操作,或用户正在操作时的提示信息。
Toast 可以显示文字,图片信息
最简单用法, Toast.makeText(context,”信息”,Toast.short).show();