setResult 不返回预期结果,当与 startActivityForResult 一起使用时



调用活动代码:

Intent intent = new Intent(MainActivity.this, BuyActivity.class);
startActivityForResult(intent, BuyActivity.BUY_REQUEST_CODE);

调用活动结果处理程序:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("billing","Got response from buy activity. resultCode = " + requestCode);
if(requestCode== BUY_REUEST_CODE){
boolean buyStatus= data.getBooleanExtra(BuyActivity.BUY_STATUS, false);
if(buyStatus){
Log.d(Constants.APP_TAG,"purchase was successful");
enablePaidFeaturesIfRequired();
}
removeAdsIfRequired();
}
}

调用的活动代码:

Intent data = new Intent();
data.putExtra(BUY_STATUS, false);
Log.d(APP_TAG,"Setting buy activity result to " + RESULT_OK);
BuyActivity.this.setResult(RESULT_OK, data);
finish();

我在处理程序中没有得到RESULT_OK,即使我在日志中看到以下内容

"Setting buy activity result to -1 ";

而是得到的结果为 1,这是RESULT_FIRST_USER,

尝试将if(requestCode== RESULT_OK){更改为if(resultCode == RESULT_OK){

在日志中,有一个错别字resultCode = " + requestCode.resultCoderequestCode不同。

相关内容

  • 没有找到相关文章

最新更新