activity1:
Intent intent2 =new Intent(this,checkactivity.class);
startActivityForResult(intent2,1000);
activity2:
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent();
setResult(result,intent);
finish();
}
activity1:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i("LOG_RES:","Checking.." + requestCode +"," + resultCode);
if (requestCode==1000){
int curProgress = progressBar.getProgress();
// if (curProgress==progressBar.getMax()){
//
// progressBar.setProgress(0);
//
// }else {
progressBar.setProgress(curProgress + resultCode*10);
// }
resultcode一直是0
点击返回键,没有正确得到回调!这是为何?因为OnBackPressed() 会默认设置setResult(RESULT_CANCELED);
解决方案:
@Override
public void onBackPressed() {
Intent intent = new Intent();
// intent.putExtra("returnFirst", "我回来了");
setResult(result,intent);
finish();
super.onBackPressed();
}
标签:onBackPressed,requestCode,Intent,intent,resultcode,onActivityResult,resultCode From: https://www.cnblogs.com/fairylandcom/p/17695259.html