Since you described your actual problem in the comments, i'll answer this here.
You shouldn't refresh you app every 5 seconds. You should react to the intents result.
Solution No 1 (ActivityForResult approach)
This is how you do it:
private static final int SELECT_PHOTO = 100;
Start the Intent
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
This part is called on a result. And you should refresh your activity in this method.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case SELECT_PHOTO:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
InputStream imageStream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
}
}
}
EDIT:
To make it clear: What happens is, that you create your activity. Call your intent. Your activity is getting paused onPause()
and after the picking it gets resumed onResume()
. So if you want to refresh your activity after it was paused. You write this behaviour in the onResume()
Method.
But still if you are starting an Intent for some result. You would use the above method to add the result to your activity.
Solution No 2 (general approach)
@Override
protected void onResume() {
super.onResume();
//Refresh here
}