My problem is: Return from an Activity to an intent.
I have the following sequence of pages:
-MainActivity
-Intent(Escolher foto)
-DadosActivity
In MainActivity I have a button to open an intent for the user to select a photo, with the following code:
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if (i.resolveActivity(MainActivity.this.getPackageManager()) != null) {
startActivityForResult(i, SELECAO_GALERIA);
}
In this attempt the user will select a photo and after that it is sent that selected item to another page, through this code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == MainActivity.this.RESULT_OK) {
Bitmap image = null;
try {
switch (requestCode) {
case SELECAO_CAMERA:
image = (Bitmap) data.getExtras().get("data");
break;
case SELECAO_GALERIA:
Uri localImagemSelecionada = data.getData();
image = MediaStore.Images.Media.getBitmap(MainActivity.this.getContentResolver(), localImagemSelecionada);
break;
}
if (image != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 70, baos);
byte[] dadosImagem = baos.toByteArray();
Intent i = new Intent(MainActivity.this, DadosPostagemActivity.class);
i.putExtra("fotoEscolhida", dadosImagem);
startActivity(i);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
In the last activity, DataActivity, the user can make some changes to the image, but my problem is when pressing the back button of the device and / or the toolbar, with the following code:
toolbar = (Toolbar) findViewById(R.id.tb_dados);
toolbar.setTitle("Adicione uma descrição");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
According to what I did in AndroidManifest
<activity
android:name=".activity.DadosPostagemActivity"
android:parentActivityName=".activity.MainActivity" />
Activity is returning to MainActivity, but I wanted to press it to return to the intent and to choose the image again.
Does anyone have any suggestions on how to do this, so that instead of returning to MainActivity, back to try so he can choose the image again?