不调用 onActivityResult() 的侦听器内的 startactivityforresult()

startactivityforresult() inside a listener not calling onActivityResult()

我知道在 SO 上有很多类似的问题,但是 none 解决了我的问题。

我在搜索栏侦听器中调用 startActivityForResult。但是,onActivityResult 没有被调用。这是我的代码。可能出了什么问题?

public class PeopleActivity extends SherlockFragment {

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    volumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            int progressChanged = 0;

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                progressChanged = progress;
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {


                Intent in = new Intent(getActivity(), com.mytest.mytestninja.RangingActivity.class);
                getActivity().startActivityForResult(in, 1);


            }

        });


}
@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        rangeValue.setText("CALLED");
    }

}

RangingActivity.java

public class RangingActivity extends Activity
@Override
    protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_ranging);

            Intent returnIntent = new Intent();
            returnIntent.putExtra("result", firstBeacon.toString());
            setResult(RESULT_OK, returnIntent);
            finish();
 }
}

更新

Activity 其中使用了 PeopleActivity 片段:

public class DrawerFrontActivity extends SherlockFragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bar = getSupportActionBar();
        Drawable myIcon = getResources().getDrawable( R.drawable.bluebar);
        bar.setBackgroundDrawable(myIcon);

        SherlockFragment fragment;
        fragment = new PeopleActivity();

        FragmentTransaction transaction =    getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.rlDrawerHome, fragment);       
        transaction.commit();

        setTitle("Home");
        bar.setTitle("Home");
}
}

您似乎在调用 getActivity().startActivityForResult(in, 1);,它会将结果传回给 activity,而不是自行分段。

尝试使用 PeopleActivity.this.startActivityForResult(in, 1);,这应该会将结果传回片段。

请参阅此答案了解更多详情:

找到答案了。 问题是因为我没有在片段 activity DrawerFrontActivity 中调用 super.onactivityresult。因此