When I select the image it saves it well and I can open it in other activitys when I close and open the app and the image does not appear in any activity, the same thing happens to me with audio files that I put in other activites what am I doing wrong in the manifest I have permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
public class llamador extends AppCompatActivity {
ImageView imagen;
EditText edit_txt_1,edit_txt_2;
Button btn_guardar;
private static final int PICK_IMAGE = 100;
public Uri imagenUri;
public SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_llamador);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Toolbar myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
myToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.atras));
myToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
edit_txt_1=findViewById(R.id.remitente);
edit_txt_2=findViewById(R.id.numero);
btn_guardar=findViewById(R.id.hecho);
imagen=findViewById(R.id.setimage);
prefs = getSharedPreferences("MisPreferencias", this.MODE_PRIVATE);
edit_txt_1.setText(prefs.getString("nombre","hermosa"));
edit_txt_2.setText(prefs.getString("numero","desconocido"));
imagenUri = Uri.parse(prefs.getString("imagenUri", null));
imagen.setImageURI(imagenUri);
imagen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showalertforcreatingboard();
}
});
btn_guardar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String nombre,numero;
nombre=edit_txt_1.getText().toString();
numero=edit_txt_2.getText().toString();
shareonprefrence(numero,nombre);
Intent j1=new Intent(llamador.this,MainActivity.class);
startActivity(j1);
}
});
}
private void showalertforcreatingboard(){
AlertDialog.Builder builder=new AlertDialog.Builder(this);
View viewinflater= LayoutInflater.from(this).inflate(R.layout.imagen,null);
builder.setView(viewinflater);
final Button input2=viewinflater.findViewById(R.id.ponimagen);
final Button input3=viewinflater.findViewById(R.id.quitaimagen);
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
final AlertDialog dialog=builder.create();
input2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cam(view);
dialog.dismiss();
}
});
input3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
imagen.setImageResource(R.drawable.user);
Uri uriImage = Uri.parse("android.resource://" + getPackageName() +"/"+R.drawable.user);
shareonprefrenceIma(uriImage);
dialog.dismiss();
}
});
dialog.show();
}
private void shareonprefrence(String numero,String nombre) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString("numero", numero);
editor.putString("nombre",nombre);
editor.apply();
}
public void cam(View view) {
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(resultCode == RESULT_OK && requestCode == PICK_IMAGE){
imagenUri = data.getData();
imagen.setImageURI(imagenUri);
shareonprefrenceIma(imagenUri);
}
}
private void shareonprefrenceIma(Uri imageUri) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString("imagenUri", imageUri.toString());
editor.apply();
}
}