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

    1、Activity跳转

    Intent intent = new Intent(MainActivity.this,NextActivity.class);
    startActivity(intent);
    
    

    跳转到NextActivity

    2、带数据跳转

    Intent intent = new Intent(MainActivity.this,NextActivity.class);
    intent.putExtra("name","YinTing");
    Bundle bundle = new Bundle();
    bundle.putInt("age",22);
    bundle.putChar("bood",'b');
    intent.putExtra("bundle",bundle);
    startActivity(intent);

    3、接收返回值跳转

    Intent intent = new Intent(MainActivity.this,NextActivity.class);
    intent.putExtra("name","YinTing");
    Bundle bundle = new Bundle();
    bundle.putInt("age",22);
    bundle.putChar("bood",'b');
    intent.putExtra("bundle",bundle);
    MainActivity.this.startActivityForResult(intent,1);

    必须复写onActivityResult该方法。

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode==1&&resultCode==1001){
    String name= data.getStringExtra("name");
    Toast.makeText(MainActivity.this,"---->"+name,Toast.LENGTH_LONG).show();
    }

    } NextActivity结束时带数据返回。


    Intent intent=new Intent();
    intent.putExtra("name","YangYi");
    NextActivity.this.setResult(1001,intent);
    NextActivity.this.finish();

    4、Android生命周期

    5、Activity现场保护

  • 相关阅读:
    django初识
    django前奏
    前端之bootstrap
    前端之jQuery
    前端基础之BOM和DOM操作
    前端之js
    前端之css(二)
    前端之css(一)
    html之form表单
    前端之html
  • 原文地址:https://www.cnblogs.com/swordyt/p/5479878.html
Copyright © 2011-2022 走看看