Android 知识点(Activity,Service,BroadcastReceiver)

Activity

    android应用程序的组件,生命周期、状态转换是关键。

    状态装换:Actived、Paused、Stopped、Killed;

    生命周期:onCreate、onStart、onResume、onPause、onStop、onDestory

     

    参考:http://www.ibm.com/developerworks/cn/opensource/os-cn-android-actvt/

    Activity之间的通信通过Intent进行消息传递, Intent可以包含调用目标,Activity过滤条件(Action、Data、Category),需要传递的信息(Data、Extras、Flags)。参考:http://blog.csdn.net/lmhit/article/details/5576250

 Service

    用于长时间在后台执行任务的组件。

    生命周期:

        通过startService开始的service,生命周期如图左,不随调用者消亡;通过bindService开始的service,生命周期如图右,随调用者消亡。

        

 Broadcast Receiver

    接收系统和应用中的广播。

    注册Receiver:

        1. 创建一个BroadcastReceiver的子类对象,重载onReceive方法(用于处理广播信息);

        2. 为Receiver对象创建IntentFilter对象,定义接收的广播的Action;

        3. 动态注册Receiver

            Intent android.content.ContextWrapper.registerReceiver(BroadcastReceiver receiver, IntentFilter filter)
    发送广播:
            void android.content.Context.sendBroadcast(Intent intent)

 

原文地址:https://www.cnblogs.com/sunnyfarmer/p/2964637.html