• Actiivity 生命周期


    Actiivity 生命周期,如下图所示: onCreate  onStart (onRestarted)  onResume  onPaused(to onResume(User navigates to the activity))  onStop  onDestroy

    onCreate 方法: 一定要实现OnCreate方法,初始化 组件和布局。

    onPause 方法:用户离开activity是的第一个被触发的方法。

    onDestroy 方法: 系统也许直接kill了process,这个方法未必会被调用。

    An activity can exist in essentially three states:

    Resumed
    The activity is in the foreground of the screen and has user focus. (This state is also sometimes referred to as "running".)
    Paused
    Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity is partially transparent or doesn't cover the entire screen. A paused activity is completely alive (the Activity object is retained in memory, it maintains all state and member information, and remains attached to the window manager), but can be killed by the system in extremely low memory situations.
    Stopped
    The activity is completely obscured by another activity (the activity is now in the "background"). A stopped activity is also still alive (the Activity object is retained in memory, it maintains all state and member information, but is not attached to the window manager). However, it is no longer visible to the user and it can be killed by the system when memory is needed elsewhere.

    两个Activity跳转时的生命周期方法调用顺序, 例如 Activity A 跳转到 Activity B:

    1. Activity A's onPause() method executes.     //先执行A的onPause方法
    2. Activity B's onCreate(), onStart(), and onResume() methods execute in sequence. (Activity B now has user focus.)  //Activity B's onCreate、onStart、onResume方法
    3. Then, if Activity A is no longer visible on screen, its onStop() method executes. // 执行A的onStop方法

    综上,如果有数据交换、交互,请在A的onPause里面执行,否则B启动了也找不到新数据。

  • 相关阅读:
    linux process management
    intel edison with grove lcd
    ODBC、OLEDB和ADO关系
    在线并使用数据库来推断在线
    大约laravel错误的解决方案
    cocos2dx-3.1加入cocosStudio参考库 libCocosStudio
    【甘道夫】基于Mahout0.9+CDH5.2执行分布式ItemCF推荐算法
    格式字符串分配stl::string
    希望开发一个指针的元素
    [Now] Configure secrets and environment variables with Zeit’s Now
  • 原文地址:https://www.cnblogs.com/amosleaf/p/3756238.html
Copyright © 2020-2023  润新知