作者:黑暗行动
原文:https://blog.csdn.net/chy2z/article/details/80080472
问题1:发现 startActivityForResult 启动非 launcherMode=" standard " 的Activity会报错;
解决方法: 设置 launcherMode=" standard "
问题2:发现Activity1使用startactivityforresult方法跳转到Activity2,当点击back键时会报错;
解决方法:1 (重写onBackPressed)
@Override
public void onBackPressed() {
//数据是使用Intent返回
Intent intent = new Intent();
//把返回数据存入Intent
intent.putExtra(BACK_CODE, BACK_CODE_NO);
//设置返回数据
this.setResult(RESULT_OK, intent);
//关闭Activity
this.finish();
}
解决方法:2 (监听返回键点击事件)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK )
{
//数据是使用Intent返回
Intent intent = new Intent();
intent.putExtra(BACK_CODE, BACK_CODE_NO);
this.setResult(RESULT_OK, intent);
this.finish();
}
return false;
}