我可以在onActivityResult回调中获取原始请求数据(intent extras)吗?

时间:2010-06-20 02:11:49

标签: android

好奇,如果我可以调用某些第三方活动,然后在onActivityResult中读取我的原始意图数据。

1 个答案:

答案 0 :(得分:3)

我对我没有任何意义,真的......无论如何,因为onActivityResult将始终是启动第三方活动的同一Activity的一部分,您只需保存该数据在你的活动的某个地方。例如:

private Intent intentForThat3rdPartyActivity = null; // long name, huh?

public void hereYouLaunchThings(){
    if( intentForThat3rdPartyActivity == null ){
        intentForThat3rdPartyActivity = new Intent(YourActitity.this, The3rdPartyActivity.class);
        intentForThat3rdPartyActivity.putExtra("weird", "data");
    }
    startActivityForResult(intentForThat3rdPartyActivity, 9999);
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
                                 Intent data) {
    // this should have the same data you passed
    String foo = intentForThat3rdPartyActivity.getStringExtra("weird");
}