Android 如何从为结果启动的活动返回字符串
我已经为result启动了活动,但是如何从该活动返回类似字符串的参数呢?说明了一切。通过调用setResult设置结果,并在onActivityResult方法中读取结果。只需使用以下代码块:Android 如何从为结果启动的活动返回字符串,android,Android,我已经为result启动了活动,但是如何从该活动返回类似字符串的参数呢?说明了一切。通过调用setResult设置结果,并在onActivityResult方法中读取结果。只需使用以下代码块: Intent intent=new Intent(); intent.putExtra("RESULT_STRING", string); setResult(RESULT_OK, intent); finish(); 在调用活动的OnActivityResult方法中从此意图获取值: protecte
Intent intent=new Intent();
intent.putExtra("RESULT_STRING", string);
setResult(RESULT_OK, intent);
finish();
在调用活动的OnActivityResult方法中从此意图获取值:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CREATE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
//Use Data to get string
String string = data.getStringExtra("RESULT_STRING");
}
}
}
只需在
intent
和调用setResult()
Intent data = new Intent();
data.putExtra("myobj", value);
setResult(Activity.RESULT_OK, data);