Android-image-cropper: How to customize back button on CropImageActivity

Created on 15 May 2020  路  7Comments  路  Source: ArthurHub/Android-Image-Cropper

It seems that whenever I press the back button on CropImageActivity, my app just crashes.
Is there a way to customize the back button (Top left on the UI page), so that I can take it back to my original activity,

Most helpful comment

@cgupta3131 I already fix the problem:
In the onActivityResult() method we have a variable called data, which stores the image we choose to crop. Therefore, if we press the back button, data will become null (because we did not choose an image), causing the line _val: CropImage.ActivityResult = CropImage.getActivityResult (data) _ to fail.
This were the changes that I implemented to make to my code work:
if(requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && data != null){
// Store image in the firebase storage and database logic
} else { // data is null, go back to the setup activity
val selfIntent = Intent(this@SetupActivity,SetupActivity::class.java)
selfIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
startActivity(selfIntent)

}

All 7 comments

Did you fix the problem? I ask because I have the same problem:(

@ArthurHub Can you help us please?:(

@cgupta3131 ?

Hey! I tried but was in vain!!

@cgupta3131 I already fix the problem:
In the onActivityResult() method we have a variable called data, which stores the image we choose to crop. Therefore, if we press the back button, data will become null (because we did not choose an image), causing the line _val: CropImage.ActivityResult = CropImage.getActivityResult (data) _ to fail.
This were the changes that I implemented to make to my code work:
if(requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && data != null){
// Store image in the firebase storage and database logic
} else { // data is null, go back to the setup activity
val selfIntent = Intent(this@SetupActivity,SetupActivity::class.java)
selfIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
startActivity(selfIntent)

}

Thank you @oescob16 this just helped me big time

The issue is fixed, view the last comment for more details

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gilshallem picture gilshallem  路  8Comments

eugenio-caicedo picture eugenio-caicedo  路  4Comments

Transformat picture Transformat  路  5Comments

danponce picture danponce  路  3Comments

zemingzeng picture zemingzeng  路  5Comments