I am trying to update a ImageView
from a File
, but I do not get it. Let me explain:
It is a simple app that just uploads and searches for a specific photo on the card and displays it. That makes it great. When I press the button to take a picture, I do it and keep it well, but when I return to the activity it does not show it. Of course, if I leave the app and go back, the new photo does appear. So I think that image remains in memory as such, but I'm not able to update it in the moment. I leave the code to see if they can think of something:
public class EditoNuevosClientes extends AppCompatActivity {
int posicion;
String id;
ArrayList<Cliente> clientes;
Cliente cliente=null;
EditText txtnombre;
EditText txttlf;
EditText txtmail;
EditText txtweb;
File fichero;
File foto;
ImageView fotoNuevoCliente;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edito_nuevos_clientes);
id=getIntent().getExtras().getString("id");
posicion=getIntent().getExtras().getInt("posicion");
txtnombre=(EditText)findViewById(R.id.txtnombre);
txttlf=(EditText)findViewById(R.id.txttlf);
txtmail=(EditText)findViewById(R.id.txtmail);
txtweb=(EditText)findViewById(R.id.txtweb);
fotoNuevoCliente=(ImageView)findViewById(R.id.fotoNuevoCliente);
try{
fichero=new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Reuniones"+File.separator+id, "otrosClientes.txt");
ObjectInputStream leo=new ObjectInputStream(new FileInputStream(fichero));
clientes=(ArrayList) leo.readObject();
leo.close();
cliente=clientes.get(posicion);
txtnombre.setText(cliente.getNombre());
txtnombre.setEnabled(false);
txttlf.setText(cliente.getTlf());
txtmail.setText(cliente.getEmail());
txtweb.setText(cliente.getWeb());
}catch (Exception e){
System.out.println("ERROR DE LECTURA");
Toast.makeText(this,"error de lectura",Toast.LENGTH_SHORT).show();
}
try{
foto=new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Reuniones"+File.separator+id, "fotoContactos"+File.separator+cliente.getNombre()+".jpg");
if (foto.exists()){
System.out.println("EXISTEEEEEEEEEEEEEEEE");
Picasso.with(this).load(foto).into(fotoNuevoCliente);
}
}catch (Exception e){}
}
public void aceptar(View view){
try{
cliente.setNombre(txtnombre.getText().toString());
cliente.setEmail(txtmail.getText().toString());
cliente.setTlf(txttlf.getText().toString());
cliente.setWeb(txtweb.getText().toString());
ObjectOutputStream escribo=new ObjectOutputStream(new FileOutputStream(fichero));
escribo.writeObject(clientes);
escribo.close();
}catch (Exception e){
System.out.println("FALLO DE ESCRITURA");
}
setResult(RESULT_OK);
finish();
}
public void cancelar(View view){
setResult(RESULT_CANCELED);
finish();
}
public void foto(View view){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri output = Uri.fromFile(foto);
intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
foto=new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Reuniones"+File.separator+id, "fotoContactos"+File.separator+cliente.getNombre()+".jpg");
if (foto.exists()){
System.out.println("EXISTEEEEEEEEEEEEEEEE");
Picasso.with(this).load(foto).into(fotoNuevoCliente);
}
}
}