标签:requestcode resultcode onactivityresult setresult
startActivityForResult(Intent intent,int RequestCode)用于启动另一个activity并等待其返回的结果,毋庸置疑,intent用于启动目标activity,而RequestCode的作用是什么呢?母模块startActivityForResult--触发子模块,根据不同执行结果设定resucode值,最后执行setResut并返回到木模块--母模块触发onActivityResult,根据requestcode参数区分不同子模块
eg:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data == null) return; //结果码 if (resultCode == RESULT_OK) { //处理个人资料中基本参数的修改处理 if (requestCode == 1001) { int type = data.getIntExtra(MineProfileEditUI.TYPE, 0); String value = data.getStringExtra(MineProfileEditUI.VALUE); switch (type) { //昵称 case 0: mUser.name = value; mProfileName.setText(mUser.name); break; //性别 case 1: mUser.gender = Integer.parseInt(value)+1; mProfileGender.setText(mUser.gender==1 ? "男" : "女"); break; //生日 case 2: mUser.birthday = value; mProfileBirthday.setText(mUser.birthday); break; //地址 case 3: mUser.address = value; mProfileAddress.setText(mUser.address); break; //个性签名 case 4: mUser.signature = value; mProfileSignature.setText(value); break; default: break; } } //设置圆形头像修改 else if (requestCode == FROM_ALBUM) { startPhotoZoom(data.getData()); } //剪切头像之后的请求码 else if (requestCode == FROM_CATE) { // 处理结果 Bundle extras = data.getExtras(); if (extras != null) { final Bitmap photo = extras.getParcelable("data"); new Thread(new Runnable() { @Override public void run() { String url=null; Message msg = handler.obtainMessage(); try{ url = FTPUpload.ftpUpload(getUserId(), FTPUpload.Type.IMAGE, bitmap2Stream(photo)); }catch (Exception e){ } if (TextUtils.isEmpty(url)) { msg.what = 0; } else { msg.what = 1; msg.obj = url; } handler.sendMessage(msg); } }).start(); } } } }
标签:requestcode resultcode onactivityresult setresult
原文地址:http://blog.csdn.net/zqs62761130/article/details/45227597