Problem with Android Intent

1

You will see when I do this intent:

 case ImageFormat.RAW_SENSOR: {
                DngCreator dngCreator = new DngCreator(mCharacteristics, mCaptureResult);
                FileOutputStream output = null;
                try {
                    output = new FileOutputStream(mFile);
                    dngCreator.writeImage(output, mImage);
                    Intent i=new Intent(Camera2RawFragment.this,CameraVisorActivity.class);

                    success = true;
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    mImage.close();
                    closeOutput(output);
                }
                break;
            }
            default: {
                Log.e(TAG, "Cannot save image, unexpected image format:" + format);
                break;
            }
        }

I get the following error:

  

"com.example.android.camera2raw.Camera2RawFragment" can not be   referenced from a static context

How could I solve it?

Thanks in advance.

    
asked by Gigasnike95 05.03.2017 в 18:27
source

1 answer

2

You seem to try to open a Intent using the Fragment as context, in this case Camera2RawFragment .

When opening a Activity from a Fragment you must use as context the Activity containing the Fragment :

 Intent intent = new Intent(getActivity(),CameraVisorActivity.class);
 startActivity(intent);

Open Activity from Fragment:

Intent intent = new Intent(getActivity(), NewActivity.class);
startActivity(intent);

Open Activity from Activity:

Intent intent = new Intent(this, NuevaActivity.class);
startActivity(intent);

or also

Intent intent = new Intent(ActivityActual.this, NuevaActivity.class);
startActivity(intent);
    
answered by 05.03.2017 / 22:04
source