G
G
gibsonen2017-05-12 15:19:52
Android
gibsonen, 2017-05-12 15:19:52

Does the wrong fragment get overwritten on the “tail” of the BackStack when I upload a file?

I use oneDrive sdk, I write my own program to interact with oneDrive.
I have 3 folders nested. Let's call them Folder One, Folder Two, and Folder Three. Folder one has folder two, folder two has folder three. Here is the 3 folder I am going to upload the file. The download is successful. Then I want to go back through the BackStack and this is what happens: from folder 3 I go to folder 2, from folder 2 I go back to folder 3. And folder 3 becomes root. What is the reason for this phenomenon?


Here's how the download goes

public void upload(final int requestCode) {

        final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setType(ACCEPTED_UPLOAD_MIME_TYPES);
        startActivityForResult(intent, requestCode);
    }

@Override
    public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        final LoginActivity application = (LoginActivity) getActivity();
        final IOneDriveClient oneDriveClient = application.getOneDriveClient();
        mItemId = ((LoginActivity) getActivity()).pathOneDrive;
        Log.e(TAG, "onActivityResult mITEMid: " + ((LoginActivity) getActivity()).pathOneDrive);
        if (requestCode == REQUEST_CODE_SIMPLE_UPLOAD
                && data != null
                && data.getData() != null
                && data.getData().getScheme().equalsIgnoreCase(SCHEME_CONTENT)) {

            final ProgressDialog dialog = new ProgressDialog(getActivity());
            dialog.setTitle(R.string.upload_in_progress_title);
            dialog.setMessage(getString(R.string.upload_in_progress_message));
            dialog.setIndeterminate(false);
            dialog.setCancelable(false);
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dialog.setProgressNumberFormat(getString(R.string.upload_in_progress_number_format));
            dialog.show();
            final AsyncTask<Void, Void, Void> uploadFile = new AsyncTask<Void, Void, Void>() {
                @Override
                protected Void doInBackground(final Void... params) {
                    try {
                        final ContentResolver contentResolver = getActivity().getContentResolver();
                        final ContentProviderClient contentProvider = contentResolver
                                .acquireContentProviderClient(data.getData());
                        final byte[] fileInMemory = FileContent.getFileBytes(contentProvider, data.getData());
                        contentProvider.release();

                        // Fix up the file name (needed for camera roll photos, etc)
                        final String filename = FileContent.getValidFileName(contentResolver, data.getData());
                        final Option option = new QueryOption("@name.conflictBehavior", "fail");
                        oneDriveClient
                                .getDrive()
                                .getItems(((LoginActivity) getActivity()).pathOneDrive)
                                .getChildren()
                                .byId(filename)
                                .getContent()
                                .buildRequest(Collections.singletonList(option))
                                .put(fileInMemory,
                                        new IProgressCallback<Item>() {
                                            @Override
                                            public void success(final Item item) {
                                                dialog.dismiss();
                                                Toast.makeText(getActivity(),
                                                        application
                                                                .getString(R.string.upload_complete,
                                                                        item.name),
                                                        Toast.LENGTH_LONG).show();
                                                refresh(((LoginActivity) getActivity()).pathOneDrive);
                                                //getFragmentManager().popBackStack();
                                            }

                                            @Override
                                            public void failure(final ClientException error) {
                                                dialog.dismiss();
                                                if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) {
                                                    Toast.makeText(getActivity(),
                                                            R.string.upload_failed_name_conflict,
                                                            Toast.LENGTH_LONG).show();
                                                } else {
                                                    Toast.makeText(getActivity(),
                                                            application
                                                                    .getString(R.string.upload_failed,
                                                                            filename),
                                                            Toast.LENGTH_LONG).show();
                                                }
                                            }

                                            @Override
                                            public void progress(final long current, final long max) {
                                                dialog.setProgress((int) current);
                                                dialog.setMax((int) max);
                                            }
                                        });
                    } catch (final Exception e) {
                        Log.e(getClass().getSimpleName(), e.getMessage());
                        Log.e(getClass().getSimpleName(), e.toString());
                    }
                    return null;
                }
            };
            uploadFile.execute();
        }
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question