Android中Activity组件学习

Android中的四大组件:Activity、Service、BroadcastReceiver、Content Provider
Activity是一个应用程序组件,提供用户与程序交互的界面。
Activity运行机制
这里写图片描述
图片来源The Android Developer’s Guide
创建使用Activity

  1. 继承Android的Activity类
  2. 重写方法
  3. 设置显示布局
  4. 在AndroidManifest文件中,注册Activity

Activity的生命周期

  1. onCreate();创建
  2. onStart();运行
  3. onResume();获取焦点
  4. onPause();失去焦点
  5. onStop();暂停
  6. onDestroy();销毁
public class ExampleActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // The activity is being created.
    }
    @Override
    protected void onStart() {
        super.onStart();
        // The activity is about to become visible.
    }
    @Override
    protected void onResume() {
        super.onResume();
        // The activity has become visible (it is now "resumed").
    }
    @Override
    protected void onPause() {
        super.onPause();
        // Another activity is taking focus (this activity is about to be "paused").
    }
    @Override
    protected void onStop() {
        super.onStop();
        // The activity is no longer visible (it is now "stopped")
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // The activity is about to be destroyed.
    }
}

Activity的四种状态

1.活动状态(Active/Running )Activity处于界面最顶端获取焦点
2.暂停状态(Paused)Activity失去焦点,但对用户可见
3.停止信息(Stopped)Activity被完全遮挡,但保留所有状态和成员信息
4.非活动状态(Killed)Activity被停止

附Android的四种数据存储方式
—SharedPreferences
—SQLite
—File
—Content Provider

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值