Is there a method that works like start fragment for result?

后端 未结 10 1288
孤城傲影
孤城傲影 2020-12-02 09:51

I currently have a fragment in an overlay. This is for signing in to the service. In the phone app, each of the steps I want to show in the overlay are their own screens and

10条回答
  •  粉色の甜心
    2020-12-02 10:09

    There is an Android library - FlowR that allows you to start fragments for results.

    Starting a fragment for result.

    Flowr.open(RequestFragment.class)
        .displayFragmentForResults(getFragmentId(), REQUEST_CODE);
    

    Handling results in the calling fragment.

    @Override
    protected void onFragmentResults(int requestCode, int resultCode, Bundle data) {
        super.onFragmentResults(requestCode, resultCode, data);
    
        if (requestCode == REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                demoTextView.setText("Result OK");
            } else {
                demoTextView.setText("Result CANCELED");
            }
        }
    }
    

    Setting the result in the Fragment.

    Flowr.closeWithResults(getResultsResponse(resultCode, resultData));
    

提交回复
热议问题