Android開發零點起飛(第六章)筆記-從一個Activity送訊息到主Activity
01.主Activity送訊息到一個Activity
Intent intent=new Intent();
intent.setClass(this, ResultActivity.class);
Bundle bundle = new Bundle();
bundle.putString("data", "1");
intent.putExtras(bundle);
startActivityForResult(intent,0);
02.一個Activity送訊息到主Activity
setResult(RESULT_OK, intent);
finish();
03.主Activity接收回傳參數
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
switch (resultCode) {
case RESULT_OK:
String str = data.getExtras().getString("data");
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
break;
default:
break;
}
沒有留言:
張貼留言