Java - Wait for a method to execute next instruction

Asked

Viewed 865 times

2

I’m making a CRUD app on Android for the college project. I’m using a ImageButton for the person to select the image to be saved. The part of selecting the image and storing it is working fine; but the photo in the view ImageButton doesn’t change.

startActivityForResult(Intent.createChooser(galeria, "Selecione a imagem"), 32);
btimg.setImageBitmap(imagemselecionada2);

From what I understand this btimg.setImageBitmap is running before the previous instruction select an image. I would like to have it run after the startActivity above finish rotating?

1 answer

0

Good afternoon, man I once had to overwrite the method below, because after the user select the image, the Android returns to Intent and focus to his Activity and runs the method below:

@Override

protected void onActivityResult(int requestCode, int ResultCode, Intent intent){
  if(requestCode == 32){
    if(resultCode == RESULT_OK){

      //seu codigo aqui
      btimg.setImageBitmap(imagemselecionada2);
    }
}}

Maybe it’ll help you!

  • Man, thanks for the answer. But unfortunately it didn’t work. I can’t set him to take this "btimg'' because every time I put him in the Oncreate() method he keeps showing some errors. And outside the Oncreate it can not catch the btimg object. : ( What to do?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.