• Android Intent实现页面跳转


     
    Intent可以来协助完成Android各个组件之间的通信
     
    1:startActivity(intent);     //直接启动
                   /*
                   * 通过监听点击事件跳转套第二个activity
                   */
                   button=(Button) findViewById(R.id. button1);
                   button.setOnClickListener( new OnClickListener() {
                          @Override
                          public void onClick(View v) {
                               Intent intent= new Intent(MainActivity.this ,myactivity.class);
                                //通过startactivity的方式实现
                               MainActivity. this.startActivity(intent);
                         }
                  });
     
    2:startActivityForResult(intent,requestCode);     //启动之后有返回值,需要关联onActivityResult(A页面使用),setResult(B页面使用)两个方法。
         onActivityResult(int requestCode,int resultCode,Intent data)    
         setResult(resultCode,data);
    button2=(Button) findViewById(R.id.button2);
                   button2.setOnClickListener( new OnClickListener() {
                         
                          @Override
                          public void onClick(View v) {
                                // TODO Auto-generated method stub
                               Intent intent= new Intent(MainActivity.this ,myactivity.class);
                                /*
                                * 第一个参数是intent对象
                                * 第二个参数是请求的标识
                                */
                               startActivityForResult(intent, 1);
                         }
                  });
     
     
     
          /**
            * 通过startActivityForResult跳转,接受返回数据的方法
            * requestCode:请求的标识
            * resultCode 第二个页面返回的标识
            * data 第二个页面回传的数据
            */
            @Override
            protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
                   super.onActivityResult(requestCode, resultCode, data);
                   if(requestCode==1&&resultCode==2){
                         String content=data.getStringExtra("data");
                  }
           }
    stareblankly.cn
  • 相关阅读:
    linux上传文件到oss的方法
    centos6.5重装python
    nfs共享文件夹
    mysql报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    搭建网关服务器
    面试总结
    innerText兼容性问题
    Title Case
    Character frequency
    Least Common Multiple
  • 原文地址:https://www.cnblogs.com/stareblankly/p/4829263.html
Copyright © 2020-2023  润新知