Second Fragment goes to background and open same activity with first fragment. Upload image using webview

14 views Asked by At

I have one activity name is Profile activity. In this activity added one fragment name is my information fragment. Now I am calling second fragment which is contain webview with document upload functionality from the first fragment.

here is the code snippet for add 1st fragment in Profile activity.

@Override
    protected void onStart() {
        super.onStart();
        // Add Profile Fragment
        getSupportFragmentManager()
                .beginTransaction()
                .setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
                .add(R.id.container, ProfileFragment.newInstance())
                .commit();
    }

here is the code for calling 2nd fragment from 1st fragment

@Override
    public void navigateToInsuranceWebViewFragment() {
        String url = mSessionStorage.getExternalLinkUrlById(ExternalLinkData.ExternalLinkId.INSURANCEMFE);
        Fragment fragment = InsuranceExternalLinkFragment.newInstance(url,
                setExternalLinkInterface(),
                null);
        getSupportFragmentManager()
                .beginTransaction()
                .setCustomAnimations(R.anim.slidein_right, R.anim.slideout_left, R.anim.slidein_left, R.anim.slideout_right)
                .replace(R.id.container, fragment)
                .addToBackStack(null)
                .commit();
    }

Now in 2nd fragment we have upload document functionality , for the same I am using below code snippet with

@Override
                    public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {

                        if (fileCallback != null) {
                            fileCallback.onReceiveValue(null);
                        }

                        fileCallback = filePathCallback;
                        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                        i.addCategory(Intent.CATEGORY_OPENABLE);
                        i.setType("*/*");
                        startActivityForResult(Intent.createChooser(i, "File Browser"),UPLOAD_DOCUMENT_CODE);
                        return true;
                    }

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode != UPLOAD_DOCUMENT_CODE || fileCallback == null) {
            return;
        }

        if (resultCode == RESULT_CANCELED) {
            // this is important, call the callback with null parameter
            this.fileCallback.onReceiveValue(null);
        } else if (resultCode == RESULT_OK) {
            Uri[] result = null;
            String dataString = data.getDataString();
            if (dataString != null) {
                result = new Uri[]{ Uri.parse(dataString) };
            }
            handleResult(result);
        }
    }

    private void handleResult(Uri[] result) {
        if (getActivity() instanceof ProfileActivity) {
            getActivity().runOnUiThread(()-> {
                fileCallback.onReceiveValue(result);
                fileCallback = null;
            });
        }
    }

The issue is after selection of image from file manager , 2nd fragment is goes to background and profile activity reloads with 1st fragment.

Is this issue with fragment transactions, webview image upload or navigate back to profile activity with 2nd fragment(web view fragment) from file manager activity ?

0

There are 0 answers