• android intent 跳转


    转自:http://blog.sina.com.cn/s/blog_7309444701014u2d.html

    一、不需要返回值的跳转

    Intent intent=new Intent();

    intent.setClass(目前的acitivy.this, 目标activity.class);

    startActivity(intent);

    二、需要返回值的跳转

    Intent intent=new Intent();

    intent.setClass(发出请求的acitivy.this, 目标activity.class);

    startActivityForResult(intent, 状态值(int类型));

    状态值作为接收目标返回值的验证。目标activity 关闭才能返回发出请求的activity

    例如:

      1、请求页面

    public class MainActivy extends Activity {
       
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Intent intent=new Intent();
            intent.setClass(MainActivy.this, ReceiveMSG.class);
            startActivityForResult(intent, 0);      
        }

    requestCode 接收返回的状态值

    resultCode :RESULT_OK  RESULT_CANCELED 可以自己赋值,按返回键时,系统默认赋值为:RESULT_CANCELED

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode==0) {
                if (resultCode==RESULT_OK) {
                    Toast.makeText(this, "Send SMS RESULT_OK", Toast.LENGTH_SHORT).show();
                }else if (resultCode==RESULT_CANCELED) {
                    Toast.makeText(this, "result cancel", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(this, resultCode, Toast.LENGTH_SHORT).show();
                }
            }else {
                Toast.makeText(this, "requsetcode not 0", Toast.LENGTH_SHORT).show();
            }
           
        }
    }

    2、接收返回值界面

    public class ReceiveMSG extends Activity{

        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);        
            ReceiveMSG.this.setResult(RESULT_OK);
            this.finish();       
        }
    }

  • 相关阅读:
    LinkedList的实现源码分析
    ArrayList实现源码分析
    探索HashMap实现原理及其在jdk8数据结构的改进
    Maven的安装使用以及 Maven+Spring hello world example
    RedisHelper帮助类
    Stream 和 byte[] 之间的转换
    WCF For Silverlight跨域策略
    Linq Query常见错误
    Linq to Sharepoint--如何获取Linq Query 生成的CALM
    如何使用代码备份SQL Server数据库
  • 原文地址:https://www.cnblogs.com/songling/p/3810261.html
Copyright © 2020-2023  润新知