Android Activity

先说一下 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在前台运行,并拥有焦点,那么他是activerunning

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();

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值