Autore Topic: Gallery che crasha  (Letto 374 volte)

Offline x69asterix2

  • Utente junior
  • **
  • Post: 127
  • Respect: +1
    • Mostra profilo
Gallery che crasha
« il: 01 Novembre 2014, 13:27:54 CET »
0
Ciao,
ho il seguente problema:
lanciando:
Codice: [Seleziona]
            Intent i = new Intent(
                   Intent.ACTION_PICK,
                   android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, 1);

A volte nessun problema, ma a volte succede che l'app mi va in errore e sinceramente non capisco il perchè!
codice errore logcat:
Codice: [Seleziona]
E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.OutOfMemoryError
            at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
            at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
            at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:378)
            at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:417)
            at magica.messaggio.MyActivity.incoming(MyActivity.java:482)
            at magica.messaggio.MyActivity.onActivityResult(MyActivity.java:452)
            at android.app.Activity.dispatchActivityResult(Activity.java:5515)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3431)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3478)
            at android.app.ActivityThread.access$1200(ActivityThread.java:157)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5319)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            at dalvik.system.NativeStart.main(Native Method)
e questo è il codice:
Codice: [Seleziona]
@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode >= 0 && resultCode == RESULT_OK) {
            switch (requestCode) {
                case 0:
                    ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                    //   data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                    EditText edtSpeak = (EditText) findViewById(R.id.edtMsg);
                    edtSpeak.setText(text.get(0));
                    break;

                case 1:

                    Uri selectedImage = data.getData();
                    if (selectedImage != null) {
                        //      pb_progress = ProgressDialog.show(this, "Trasferimento file...", "Attendere prego...", true, false);
                        String[] filePathColumn = {MediaStore.Images.Media.DATA};
                        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                        cursor.moveToFirst();

                        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                        String picturePath = cursor.getString(columnIndex);
                        cursor.close();

                        String selectedImagePath;
                        selectedImagePath = ImageFilePath.getPath(getApplicationContext(), selectedImage);
                        imagePath = selectedImagePath;
                        fileName = picturePath.substring(imagePath.lastIndexOf("/") + 1);

                          incoming();
                    }

                    break;
                case 2:

                    break;
            }
        }
    }

    private void incoming(){

        final RelativeLayout mContainerView = (RelativeLayout) findViewById(R.id.frameLayout);
        mContainerView.removeView(mView);
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.activity_image__rotate, null);
        img2 = (ImageView) mView.findViewById(R.id.img_send_foto);
        Button btn_foto90 = (Button) mView.findViewById(R.id.btn_rotate90);
        Button btn_foto270 = (Button) mView.findViewById(R.id.btn_rotate270);
        Button btn_foto_send = (Button) mView.findViewById(R.id.btn_img_f);
        TextView txt_ = (TextView) mView.findViewById(R.id.txt_rotate_path);
        txt_.setText(imagePath + "\n" + "File: " + fileName);

      //  InputStream inputStream = null;
   //     try {
     //       inputStream = getContentResolver().openInputStream(selectedImage);
      //      BufferedInputStream bis = new BufferedInputStream(inputStream);
      //      Bitmap bitmap = BitmapFactory.decodeStream(bis);


            Bitmap src = BitmapFactory.decodeFile(imagePath);
            img2.setImageBitmap(getResizedBitmap(src, 280, 345));

            mContainerView.addView(mView);
   //     } catch (FileNotFoundException e) {
    //        e.printStackTrace();
    //    }
....
avete un suggerimento?

Post unito: 01 Novembre 2014, 15:55:26 CET
OooooK!
risolto con BitmapFactory.Options
« Ultima modifica: 01 Novembre 2014, 15:55:26 CET da x69asterix2, Reason: Merged DoublePost »