setResult(RESULT_OK,intent)回传不了值,为什么?总是null
package cao.org.android.fan;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class First_Activity extends Activity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Bundle bundle=data.getExtras();
String str_1=bundle.getString("edit_1");
String str_2=bundle.getString("edit_2");
System.out.println(str_1+"111111111");
System.out.println(str_2+"22222222222");//回传的这两个值总是null值,为什么?帮帮忙,解释下,谢谢各位了
edit_1.setText(str_1);
edit_2.setText(str_2);
}
private EditText edit_1;
private EditText edit_2;
private Button but_1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edit_1=(EditText)findViewById(R.id.edit_1);
edit_2=(EditText)findViewById(R.id.edit_2);
but_1=(Button)findViewById(R.id.but_1);
but_1.setOnClickListener(but_1_listener);
}
private OnClickListener but_1_listener=new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(First_Activity.this,Second_Activity.class);
Bundle bundle=new Bundle();
String str1=edit_1.getText().toString();
String str2= edit_2.getText().toString();
bundle.putString("edit1",str1 );
bundle.putString("edit2",str2);
intent.putExtras(bundle);
startActivityForResult(intent, 0);
}
};
}
package cao.org.android.fan;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Second_Activity extends Activity {
// private EditText edit_3;
// private EditText edit_4;
private Button but_2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondmain);
but_2=(Button)findViewById(R.id.but_2);
but_2.setOnClickListener(but_2_listener);
}
private OnClickListener but_2_listener=new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("bbbbbbbbbbbbb");
Intent intent=getIntent();
Bundle dBundle=intent.getExtras();
Second_Activity.this.setResult(RESULT_OK,intent); //回传不了值,回传的是null的?
finish();
}
};
}
不知道为什么总是使用不了setResult(RESULT_OK,intent);各位懂得帮帮忙了,谢谢了。。
[解决办法]
key值在传入的时候是“edit1”
返回取值的时候是“edit_1”