WEB开发网
开发学院手机开发Android 开发 Android 2.0 中调用 subActivity 时数据传送 阅读

Android 2.0 中调用 subActivity 时数据传送

 2010-03-25 17:03:00 来源:WEB开发网   
核心提示:Android---2.0与之前的1.6中的数据传送方式不太一样,最大区别:1.6Java代码protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras){ /* Place out code t

Android---2.0与之前的1.6中的数据传送方式不太一样。最大区别:

1.6

Java代码

protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras)

{ /* Place out code to react on Activity-Result here. */

super.onActivityResult(requestCode, resultCode, data, extras);

}

MySecondActivity.this.setResult(1, keyword);

protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras)

{ /* Place out code to react on Activity-Result here. */

super.onActivityResult(requestCode, resultCode, data, extras);

}

MySecondActivity.this.setResult(1, keyword);

2.0

Java代码

protected void onActivityResult(int requestCode, int resultCode, Intent i)

{

super.onActivityResult(requestCode, resultCode, i);

}

protected void onActivityResult(int requestCode, int resultCode, Intent i)

{

super.onActivityResult(requestCode, resultCode, i);

}

应该说2.0中将data以及extras都放进了intent,封装的更好了.使用中注意即可.

Java代码

//传送时

Intent data = new Intent();

data.putExtra("Data", search.getText().toString());

subActivityWithResult.this.getIntent().putExtra("Data",

search.getText().toString());

subActivityWithResult.this.setResult(SUCCESS_RETURN_CODE, data);

subActivityWithResult.this.finish();

//接收时

protected void onActivityResult(int requestCode, int resultCode, Intent i)

{

super.onActivityResult(requestCode, resultCode, i);

if(requestCode==SUB_ACTIVITY_REQUEST_CODE)

{

data=i.getExtras().getString("Data"));

}

}

Tags:Android 调用 subActivity

编辑录入:coldstar [复制链接] [打 印]
赞助商链接