zoukankan      html  css  js  c++  java
  • Android Activity生命周期

    onCreate(创建) 、onStart(激活) 、onResume(恢复) 、onPause(暂停) 、onStop(停止) 、onDestroy(销毁) 、onRestart(重启)

    Activity starts -->onCreate()-->onStart()-->onResume()-->activity is running--another activity comes in front of this activity-->onPause()--the activity is no longer visivble-->onStop()-->onDestroy()-->activity is shut down

    notes:

            When the “onPause()“excute,other applications need memory ,then Process is killed(User navigates back to activity),last excute onCreate()。

     When  the “onPause()“excute,the activity comes to the foreground,so it will excute onRestart(),last excute onstart()。

    各个函数使用的时间:

    1、onCreate()    
    Acitivity首次创建时被调用。用于设置Acitivity的布局文件,绑定按钮监听器等一些普通静态操作。

    2、onStart()
    Acitivity对用户可见时被调用。

    3、onResume()
    Acitivity获得用户焦点,即用户可操作该Acitivity时被调用。

    4、onPause()
    应用程序启动了其它Acitivity时被调用。一般用于保存当前Acitivity中的数据。

    5、onStop()
    Acitivity不可见时被调用。

    6、onRestart()
    已停止的Acitivity重新启动时被调用。

    7、onDestroy()
    调用Acitivity的finish()方法或Android系统资源不足时被调用。

  • 相关阅读:
    171-滑动窗口问题
    170-133. 克隆图
    169-150. 逆波兰表达式求值
    windows相对路径设置与取消小工具[提效]
    Sword 38
    Sword 33
    Sword 28
    Sword 26
    Sword 12
    Sword 07
  • 原文地址:https://www.cnblogs.com/shihao/p/2695420.html
Copyright © 2011-2022 走看看