0

問題があります。表示されていない onActivityResult 関数から実行されている 3 つのフラグメントがあります。フラグメントが実行されていて、それらと対話できるため (たとえば、[戻る] ボタンをクリックすると、フラグメントが表示されてからロールアウトされます)、表示されないため、これは奇妙です。onActivityResult 関数の外側でフラグメントをテストしました(ボタンのクリックで実行します)が、正常に動作します。これに関するもう1つの奇妙な点は、問題がタブレットでのみ発生し、電話では正常に機能することです.

以下は onActivityResult コードです。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    System.out.println("ACTIVITY RESULT");
    System.out.println("REQUEST CODE >>>>> " + requestCode);

    if (requestCode == webview) {

        // if (resultCode == RESULT_OK) {

        System.out.println("RESULT WEBVIEW");

        System.out.println(data.getStringExtra("URL"));

        Bundle args = new Bundle();
        args.putString("URL", data.getStringExtra("URL"));
        args.putString("List Name", currentList);
        args.putInt("List Position", pos);

        URLFragment urlFrag = new URLFragment();

        urlFrag.setArguments(args);
        FragmentTransaction transaction = getSupportFragmentManager()
                .beginTransaction();
        transaction.setCustomAnimations(R.anim.in_from_right,
                R.anim.out_from_left);

        System.out.println("FRAG CONTAINER >>>> "
                + findViewById(R.id.fragment_container));
        System.out.println("ARTICLE FRAG >>>> "
                + findViewById(R.id.article_fragment));

        if (findViewById(R.id.fragment_container) != null) {
            transaction.add(R.id.fragment_container, urlFrag,
                    "URL Fragment");
            transaction.addToBackStack(null);
        } else {
            transaction.add(R.id.article_fragment, urlFrag, "URL Fragment");
        }

        transaction.commit();

        // }
        // if (resultCode == RESULT_CANCELED) {
        // // Write your code if there's no result
        // System.out.println("CANCELED WEBVIEW");
        // }
    } else if (requestCode == camera) {

        if (resultCode == RESULT_OK) {

            System.out.println("RESULT CAMERA");
            System.out.println(data.getData());

            if (data.getData().toString().contains("picasa")) {
                System.out.println("UNABLE TO LOAD IMAGE");
                Toast.makeText(
                        getApplicationContext(),
                        "We are unable to load this image, please select a different one",
                        Toast.LENGTH_LONG).show();
            } else {

                if (getSupportFragmentManager().findFragmentByTag(
                        "Image Fragment") == null) {
                    GatherGalleryImages gatherImage = new GatherGalleryImages();
                    Uri selectedImageUri = data.getData();
                    String[] projection = { MediaStore.Images.Media.DATA };
                    Cursor cursor = managedQuery(selectedImageUri,
                            projection, null, null, null);

                    String selectedImagePath = gatherImage.getPath(cursor);

                    System.out.println(selectedImagePath);

                    Bundle args = new Bundle();
                    args.putString("List Name", currentList);
                    args.putInt("List Position", pos);
                    args.putString("Image Location", selectedImagePath);

                    CameraItemFragment newFragment = new CameraItemFragment();
                    newFragment.setArguments(args);
                    FragmentTransaction transaction = getSupportFragmentManager()
                            .beginTransaction();
                    transaction.setCustomAnimations(R.anim.in_from_right,
                            R.anim.out_from_left);

                    if (findViewById(R.id.fragment_container) != null) {
                        transaction.add(R.id.fragment_container,
                                newFragment, "Image Fragment");
                        transaction.addToBackStack(null);
                        transaction.commit();
                    } else {

                        transaction.add(R.id.article_fragment, newFragment,
                                "Image Fragment");
                        // transaction.addToBackStack(null);
                        transaction.commit();
                    }
                }

            }
        }
        if (resultCode == RESULT_CANCELED) {
            // Write your code if there's no result
            System.out.println("CANCELED CAMERA");
        }
    } else if (requestCode == IntentIntegrator.REQUEST_CODE) {

        if (resultCode != RESULT_CANCELED) {
            IntentResult scanResult = IntentIntegrator.parseActivityResult(
                    requestCode, resultCode, data);
            if (scanResult != null) {
                String upc = scanResult.getContents();

                // put whatever you want to do with the code here
                System.out.println("UPC >>>> " + upc);
                Intent mainIntent = new Intent(MainActivity.this,
                        Webview_Activity.class);
                mainIntent.putExtra("upc", upc);
                mainIntent.putExtra("listName", currentList);

                MainActivity.this.startActivityForResult(mainIntent, 1);
            }
        }
    } else if (requestCode == cam) {
        System.out.println("CAMERA INTENT 0");

        if (resultCode == RESULT_OK) {

            Bitmap photo = (Bitmap) data.getExtras().get("data");

            // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
            Uri tempUri = getImageUri(getApplicationContext(), photo);

            // CALL THIS METHOD TO GET THE ACTUAL PATH
            File finalFile = new File(getRealPathFromURI(tempUri));

            String selectedImagePath = finalFile.getAbsolutePath();

            Bundle args = new Bundle();
            args.putString("List Name", currentList);
            args.putInt("List Position", pos);
            args.putString("Image Location", selectedImagePath);

            CameraItemFragment newFragment = new CameraItemFragment();
            newFragment.setArguments(args);
            FragmentTransaction transaction = getSupportFragmentManager()
                    .beginTransaction();
            transaction.setCustomAnimations(R.anim.in_from_right,
                    R.anim.out_from_left);

            if (findViewById(R.id.fragment_container) != null) {
                transaction.add(R.id.fragment_container, newFragment,
                        "Image Fragment");
                transaction.addToBackStack(null);
                transaction.commit();
            } else {

                transaction.add(R.id.article_fragment, newFragment,
                        "Image Fragment");
                // transaction.addToBackStack(null);
                transaction.commit();
            }
        }

        if (resultCode == RESULT_CANCELED) {
            // Write your code if there's no result
        }
    } else if (resultCode == RESULT_CANCELED) {

    }
}

}

これは私が遭遇した最も奇妙な問題の 1 つです。

4

0 に答える 0