title: Getting null value from method outside OnCreate on real device
body: <p>I have this quite simple app, to upload pictures to Firebase directly from camera, written following the original documentation from Android developpers page. It works very well on emulators, but on my Galaxy S4 it crashes. The variable <code>imageFileName</code> gets null on <code>onActivityResult</code>, but only in GS4. Here is what is get in emulators:</p>
  
  <p><em>I/TAG 0:: FILENAME JPEG_20170420_005617_</em></p>
  
  <p><em>I/TAG 1:: FILENAME JPEG_20170420_005617_</em></p>
  
  <p><strong>And here is what is get in GS4:</strong></p>
  
  <p><em>I/TAG 0:: FILENAME JPEG_20170420_005617_</em></p>
  
  <p><em>I/TAG 1:: FILENAME null</em></p>
  
  <p>Why it gets null out of nothing? Why on S4? Without this value I cant putFile to Firebase. Only with GS4.</p>
  
  <p>Thanks for your help.</p>
  
  <pre><code>private FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
  private StorageReference mStorage;
  private Button mSelect, mCam;
  public Uri uri, photoURI;
  private String imageFileName;
  
  private ProgressDialog mProgressDialog;
  
  private static final int GALLERY_INTENT = 2;
  private static final int CAMERA_REQUEST_CODE = 1;
  static final int REQUEST_TAKE_PHOTO = 1;
  
  String mCurrentPhotoPath;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      mStorage = FirebaseStorage.getInstance().getReference();
  
      mSelect = (Button) findViewById(R.id.first_but);
      mCam = (Button) findViewById(R.id.sec_but);
  
      mProgressDialog = new ProgressDialog(this);
  
      mCam.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              //startActivityForResult(intent, CAMERA_REQUEST_CODE);
              dispatchTakePictureIntent();
  
  
          }
      });
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if(requestCode == REQUEST_TAKE_PHOTO &amp;&amp; resultCode == RESULT_OK) {
          Log.i("TAG 1: ", "FILENAME " + imageFileName);
      }
  }
  
  private File createImageFile() throws IOException {
      // Create an image file name
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
      imageFileName = "JPEG_" + timeStamp + "_";
      File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
      File image = File.createTempFile(
              imageFileName,  /* prefix */
              ".jpg",         /* suffix */
              storageDir      /* directory */
      );
  
      // Save a file: path for use with ACTION_VIEW intents
      mCurrentPhotoPath = image.getAbsolutePath();
      return image;
  }
  
  private void dispatchTakePictureIntent() {
      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      // Ensure that there's a camera activity to handle the intent
      if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
          // Create the File where the photo should go
          File photoFile = null;
          try {
              photoFile = createImageFile();
          } catch (IOException ex) {
              // Error occurred while creating the File
          }
          // Continue only if the File was successfully created
          if (photoFile != null) {
              photoURI = FileProvider.getUriForFile(this,
                      "com.example.android.fileprovider",
                      photoFile);
              Log.i("TAG 0: ", "FILENAME " + imageFileName);
              takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
              startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
          }
      }
  }
  </code></pre>