• android 点击返回键 以及 加载activity 生命周期 记录。。。,一目了然


    简叙 Activity 生命周期及android 返回按钮捕捉

     
    复制代码
      @Override
    protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState); //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected void onStart() {
    System.out.println("---------------onStart---------------");
    super.onStart(); //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected void onRestart() {
    System.out.println("---------------onRestart---------------");
    super.onRestart(); //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected void onResume() {
    System.out.println("---------------onResume---------------");
    super.onResume(); //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected void onPostResume() {
    System.out.println("---------------onPostResume---------------");
    super.onPostResume(); //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected void onPause() {
    System.out.println("---------------onPause---------------");
    super.onPause(); //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected void onStop() {
    System.out.println("---------------onStop---------------");
    super.onStop(); //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    protected void onDestroy() {
    System.out.println("---------------onDestroy---------------");
    super.onDestroy(); //To change body of overridden methods use File | Settings | File Templates.
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode== KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
    Toast.makeText(_context,"点击了返回【onKeyDown】",Toast.LENGTH_LONG).show();
    System.out.println("---------------onKeyDown---------------");
    this.onBackPressed();
    return true; //确认返回了
    }
    return false; //不允许返回
    }

    @Override
    public void onBackPressed() {

    Toast.makeText(_context,"点击了返回【onBackPressed】",Toast.LENGTH_LONG).show();
    System.out.println("---------------onBackPressed---------------");
    super.onBackPressed();
    }
    复制代码

    简单的说,

       当activity 启动的时候会启动以下方法,按先后顺序

    onCreate->onStart->onResume->onPostResume

    当按返回的时候,也就是结束这个Activity的时候,先后顺序是:

    onPase->onStop->onDestroy

  • 相关阅读:
    第27篇-虚拟机字节码指令之操作数栈管理指令
    第26篇-虚拟机对象操作指令之putstatic
    第25篇-虚拟机对象操作指令之getfield
    第24篇-虚拟机对象操作指令之getstatic
    第23篇-虚拟机字节码指令之类型转换
    第22篇-虚拟机字节码之运算指令
    第20篇-加载与存储指令之ldc与_fast_aldc指令(2)
    第19篇-加载与存储指令(1)
    第18章-x86指令集之常用指令
    第17章-x86-64寄存器
  • 原文地址:https://www.cnblogs.com/duanweishi/p/4528170.html
Copyright © 2020-2023  润新知