zoukankan      html  css  js  c++  java
  • Application's Life Cycle

    Android Applications
    An application consists of one or more components that are defined in the application's manifest file. A component can be one of the following:
    1. An Activity
    2. A Service
    3. A broadcast receiver
    4. A content provider
     
    1. Activity
    An activity usually presents a single visual user interface from which a number of actions could be performed. Altough activities work together to form a cohesive user interface, each activity is independent of the others. Typically, one of the activities is marked as the firstone that should be presented to the user when the application is launched. Moving from one activity to another is accomplished by having the current activity start the next one through so called intents.
     
    2. Service
    A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running). While connected, you can communicate with the service through an interface that the service exposes.
     
    3. Broadcast receiver
    A broadcast receiveris a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in system code (eg. “you got mail“) but any other applications can also initiate broadcasts. Broadcast receivers do not display a user interface. However, they may start an activity in response to the information they receive, or -as services do -they may use the notification manager to alert the user.
     
    4. Content provider
    A content providermakes a specific set of the application's data available to other applications.
    The data usually is stored in the file system, or in an SQLite database.
    The content provider implements a standard set of methods that enable other applications to retrieve and store data of the type it controls.
    However, applications do not call these methods directly. Rather they use a content resolver object and call its methods instead. A content resolver can talk to any content provider; it cooperates with the provider to manage any interprocess communication that's involved.
     
    Every Android application runs in its own process(with its own instance of the Dalvik virtual machine). Whenever there's a request that should be handled by a particular component,
    • Android makes sure that the application process of the component is running,
    • starting it if necessary, and
    • that an appropriate instance of the component is available, creating the instance if necessary.
     
    A Linux process encapsulating an Android application is created for the application when some of its code needs to be run, and will remain running until
    1. it is no longer needed, OR
    2. the system needs to reclaim its memory for use by other applications.
     
    An unusual and fundamental feature of Android is that an application process's lifetime is not directly controlled by the application itself. Instead, it is determined by the system through a combination of
    1. the parts of the application that the system knows are running,
    2. how important these things are to the user, and
    3. how much overall memory is available in the system.
     
    Component Lifecycles
    Application components have alifecycle
    1. A beginningwhen Android instantiates them to respond to intents
    2. An endwhen the instances are destroyed.
    3. In between, they may sometimes be activeor inactive, or -in the case of activities-visibleto the user or invisible.
     
    Activty Stack
    • Activities in the system are managed as an activity stack.
    • When a new activity is started, it is placed on the topof the stack and becomes the running activity --the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.
    • If the user presses the Back Button the next activity on the stack moves up and becomes active.
     
    Life Cycle States
    An activity has essentially three states:
    1. It is activeor running
    2. It is pausedor
    3. It is stopped.
     
    An activity has essentially three states:
    1. It is activeor runningwhen it is in the foregroundof the screen(at the top of the activity stack for the current task). This is the activity that is the focus for the user's actions.
    2. It is pausedif it has lost focus but is still visible to the user. 
    That is, another activity lies on top of it and that new activity either is transparentor doesn't cover the full screen. 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.
    3. It is stopped if it is completely obscuredby another activity. 
    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.
     
    Base on: Android Application Programming, Mr. Patrick Harubin
  • 相关阅读:
    CSS基础(二十五)--Background背景之让background-image失效
    CSS基础(二十四)--Background背景之background-image平铺图片堆叠显示
    CSS基础(二十三)--Hover鼠标悬浮变色
    Nginx_安全1
    firewalld防火墙
    shell编程习题
    linux忘记密码
    sed和awk详解
    shell正则表达式
    ssh
  • 原文地址:https://www.cnblogs.com/qwertWZ/p/2579283.html
Copyright © 2011-2022 走看看