android camera intent not working properly on some devices -


hi developing android application in trying capture image using device camera , save particular location. tried in following manner:

public class mainactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      log.i("inside on create ", "inside on create ");      capturephotoforrecordupload(); }  public void capturephotoforrecordupload() {      intent takepictureintent = new intent(mediastore.action_image_capture);     if (takepictureintent.resolveactivity(getpackagemanager()) != null) {          file storagedir = new file(environment.getexternalstoragedirectory().getpath() + "/myapp");         if(!storagedir.exists())             storagedir.mkdirs();         if(!storagedir.exists())             storagedir.mkdir();              takepictureintent.putextra(mediastore.extra_output, uri.fromfile(new file(environment.getexternalstoragedirectory().getpath() + "/myapp"+"/sample.jpg")));             startactivityforresult(takepictureintent, 7);     } }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     if (resultcode == result_ok) {     }  } } 

i facing problem in above code. when start activity opening camera. when click button again coming on create of activity , again opening camera application. correct behaviour or doing wrong? without calling on destroy of activity again coming inside on create.need help. thank you.

i had same issue on few devices when using camera. put logs in activity ondestory , see if gets called when start camera intent.

this issue occurred on devices low memory (for me older lg phone had 50+ apps installed many of them running various background services used testing) -> the camera app memory heavy , system kill process in background started it. thats why see activity going through complete lifecycle again.

edit 1:

take @ following answers:

android: activity getting destroyed after calling camera intent

trouble working camera in onactivityresult

activity gets killed after returned camera


for people solution acquired through manifest changes (see first link)

i implemented solutions described in other answers handling savedinstancestate bundle since controlling image path manually.

also see reason why activity recreated, because camera apps on phones trigger orientation changes. problem too, if not memory problem.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -