title: Why my app crashes when I run a Runnable thread in Android?
body: <p>I'm trying to run a thread when a specifically method is called. Like this:</p>
  
  <pre><code>private void changeSize(final Bitmap image) {
    Thread task = new Thread(new Runnable() {
       @Override
       public void run() {
              byte[] image;
              int width = image.getWidth();
              int height = image.getHeight();
              int newHeight = 0, newWidth = 0;
              if (width &gt; 350 || height &gt; 350) {
                  if (width &gt; height) { 
                      newHeight = 350;
                      newWidth = (newHeight * width) / height;
                  } else { 
                      nyBredden = 350;
                      newHeight = (newWidth * height) / width;
                  }
              } else {
                  Toast.makeText(context, "test", Toast.LENGTH_LONG).show();
                  }
              Bitmap sizeChanged = Bitmap.createScaledBitmap(image, newWidth, newHeight, true);
              if (sizeChanged != null) {
                  Toast.makeText(context, "test", Toast.LENGTH_SHORT).show();
              } else {
                  Toast.makeText(context, "test", Toast.LENGTH_SHORT).show();
              }
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
  
              if (sizeChanged.getHeight() &gt;= 350 || sizeChanged.getWidth() &gt;= 350) {
                  sizeChanged.compress(Bitmap.CompressFormat.JPEG, 90, stream);
              } else {
                  sizeChanged.compress(Bitmap.CompressFormat.JPEG, 100, stream);
              }
  
              image = stream.toByteArray();
              if (image != null) {
                  myImage(image); //method
                  File path = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
                  String namechanged = edMyType.getText().toString() + "_scalledDown" + ".jpg";
  
                  File file = new File(path, namechanged);
                  FileOutputStream fos = null;
                  try {
                      fos = new FileOutputStream(file);
                      fos.write(image);
                      fos.flush();
                  } catch (Exception e) {
                      e.printStackTrace();
                  } finally {
                      try {
                          if (fos != null) {
                              fos.close();
                          }
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                  }
              } else {
                  Toast.makeText(context, "test", Toast.LENGTH_SHORT).show();
              }
          }
       }
    });
    task.start(); 
  }
  </code></pre>
  
  <p>when i call this method my app crashes. I tried to debug, but i don't understand the variables for example:</p>
  
  <pre><code>task: "Thread[Thread-149,5,main]"
  hasBeenStarted = false
  </code></pre>
  
  <p>The method is called when i press a button to take a picture. Please any one knows where i did wrong or is it correct to run a thread like this? </p>