0
My problem is: Back from an Activity to an Internet.
I have the following sequence of pages:
-MainActivity
-Intent(Escolher foto)
-DadosActivity
In Mainactivity I have a button to open an Intent so that the user 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 Input the user will select a photo and after that is sent this 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, Dadosactivity, the user can make some changes to the image, but my problem is to press the button on the back of the device and/or 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 on Androidmanifest
<activity
android:name=".activity.DadosPostagemActivity"
android:parentActivityName=".activity.MainActivity" />
Activity is returning to Mainactivity, but I wanted that by pressing back on the Internet and I could choose the image again.
Does anyone have any suggestions on how to do this, so instead of going back to Mainactivity, go back to the Internet so he can choose the image again?
I’ll test here and give you a feedback! Vlww
– Luis Felipe
The only problem that I found is that, I will need to do again the code that passes the chosen image to the Data screen. If you have a way to go back to Mainactivity but with the button already the action_pick Intent already open ai n need to redo these code. would have some way?
– Luis Felipe
I edited the answer. See if it fits what you need!
– Wagner Paz