onActivityResult无法正常工作

时间:2014-11-01 20:32:54

标签: android onactivityresult

我有ExpandableListView并且在每个子元素上都有一个调用另一个(编辑)活动的按钮。

public void editSet(Set set, int groupPosition, int childPosition){
    Intent intent = new Intent(this, editSetActivity.class);
    intent.putExtra("set", set);
    intent.putExtra("groupPosition", groupPosition);
    intent.putExtra("childPosition", childPosition);
    startActivityForResult(intent, EDIT_RESPONSE);
}

点击时打开的活动有这个方法

public void save(View view){
        ***some code***
        Intent intent = new Intent(this, startWorkoutActivity.class);
        intent.putExtra("set", newSet);
        intent.putExtra("groupPosition", groupPosition);
        intent.putExtra("childPosition", childPosition);

        setResult(RESULT_OK, intent);
        Log.d("cia", "------");

        finish();
    }

但是当此活动关闭时,onActivityResult未被调用(我已经登录并且它没有显示)。 AndroidManifest没有noHistoryandroid:launchMode="singleInstance"

编辑:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("log", "*************");
        if (requestCode == EDIT_RESPONSE) {
            if (resultCode == RESULT_OK) {

                Set newSet = (Set)data.getSerializableExtra("set");
                int groupPos = (Integer)data.getSerializableExtra("groupPosition");
                int childPos = (Integer)data.getSerializableExtra("childPosition");
                Log.d(String.valueOf(groupPos), String.valueOf(childPos));
                ArrayList<Set> tempSet = (ArrayList<Set>)setList.get(groupPos);
                tempSet.set(childPos, newSet);
                setList.set(groupPos, tempSet);
                adapter.notifyDataSetChanged();
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

public void save(View view){
    ***some code***
    Intent intent = new Intent();
    intent.putExtra("set", newSet);
    intent.putExtra("groupPosition", groupPosition);
    intent.putExtra("childPosition", childPosition);

    setResult(RESULT_OK, intent);
    Log.d("cia", "------");

    finish();