假如现在有个ActivityGroup A,里面有两个子Activity B和C,在C里面跳转到另一个Activity D,然后在D里面执行了某些操作,finish了再返回D的时候,刷新D界面。该如何实现呢?
如果在C里面,c.startActivityForResult(D,0),然后在D finish()之前setResult(1),那么在C的onActivityResult里面是接收不到从D返回过来的返回码1的,也就无法刷新界面了。
解决办法是:
C启动D:
Intent intent = new Intent(C.this,D.class); getParent().startActivityForResult(intent,0);
然后在A中重写onActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(requestCode==0){ C activity =(C)getLocalActivityManager().getCurrentActivity(); activity.handleActivityResult(requestCode, resultCode, data);//把收到的消息发送给发起请求的Activity C } }
最后在C中添加handleActivityResult方法
public void handleActivityResult(int requestCode, int resultCode, Intent data){ if(resultCode == 1){//获取返回码,刷新界面 Log.i(TAG, "返回码:"+resultCode); } }