Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android system stops application when launching Media Intent

Tags:

android

I am launching a media intent to take a photo. After the user took a picture and gets back to the previous activity the whole application has restarted.

As this doesn't happen all the time, I think my application goes to the background and android kills it when the device has low memory.

Is there any way to keep my application from going to the background?

Thanks!

like image 390
timoschloesser Avatar asked Dec 05 '22 16:12

timoschloesser


1 Answers

This is normal behavior in Android, all activities currently not visible on screen (after onStop) can be killed without notice (i.e. onDestory) if the system has low memory.

This usually happens to our app on one of our test devices which has memory issues regardless of our app.

You can usually recreate this behavior when you open the camera via the intent, and then rotate the device (portrait to landscape), this will also kill and re-create your app.

To solve this you need to extend onSaveInstanceState and use the savedInstanceState parameter in your onCreate to pass from your killed instance to your new instance some important information (like "we're in the middle of getting a pic from the camera").

like image 192
marmor Avatar answered Mar 01 '23 23:03

marmor