当我从子活动返回时,不会在mainActivity中调用onActivityResult。我在儿童活动中使用finish()。你能告诉我原因吗?
先谢谢。
private void goToHomePage() {
if(connected){
basket.putString(key, "dummy");
Intent i = new Intent(Splash.this,HomePage.class);
i.putExtras(basket);
startActivityForResult(i,0);
}else{
alert();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
basket = data.getExtras();
Log.i("Splash","on activity result...");
if (resultCode == RESULT_OK){
switch(requestCode){
case 0:
wifi.disConnect();
break;
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
Log.i("HomePage","onKeyDown");
sendBack("close");
}
return super.onKeyDown(keyCode, event);
}
public void sendBack(String command) {
Intent sendBack = new Intent();
Bundle basket1 =new Bundle();
basket1.putString("command", command);
sendBack.putExtras(basket1);
setResult(RESULT_OK, sendBack);
finish();
}
答案 0 :(得分:0)
为什么有
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
你onActivityResult
中的?我想这不是必需的,并且控件正在使用此语句并在逻辑之前退出方法。与其他注释一样,如果控制到达此语句,您是否已逐步检查调试?
答案 1 :(得分:0)
当用户按下后退键时,您是否尝试将某些内容传递给主要活动?在这种情况下,试试这个:
onKeyDown()
。在儿童活动中,添加以下内容:
@Override
public void onBackPressed()
{
String command = "close";
Intent sendBack = new Intent();
Bundle basket1 =new Bundle();
basket1.putString("command", command);
sendBack.putExtras(basket1);
setResult(RESULT_OK, sendBack);
finish();
// Do not call super.onBackPressed() so as to ignore the default implementation.
}
答案 2 :(得分:0)
这是我的错误,我在onAause of mainActivity中给了finish()。这会在活动转移到儿童活动时关闭活动。再次感谢!