With Flutter image_picker we must handle the MainActivity destruction. Looking for alternative

222 views Asked by At

After reading all the image_picker plugin for Flutter readme file.

I am concerned about this:

Handling MainActivity destruction When under high memory pressure the Android system may kill the MainActivity of the application using the image_picker. On Android the image_picker makes use of the default Intent.ACTION_GET_CONTENT or MediaStore.ACTION_IMAGE_CAPTURE intents. This means that while the intent is executing the source application is moved to the background and becomes eligible for cleanup when the system is low on memory. When the intent finishes executing, Android will restart the application. Since the data is never returned to the original call use the ImagePicker.retrieveLostData() method to retrieve the lost data.

I understand this, I also have implemented the plugin and with a few intents this behavior happened.

The complexity of our app makes this "recovery" very difficult for us, so we are looking for alternatives.

We found this other plugin: CAMERA, that is a little more complicated to use but have no warnings about this issue.

¿Can any user of this plugin (CAMERA) tell me if this plugin doesnt have this 'Main Activity destruction' issue that IMAGE_PICKER has?

1

There are 1 answers

1
smorgan On BEST ANSWER

camera does not use intents; all of the UI for it is within your application. That means the application is not in the background, and is therefore not subject to cleanup.

Keep in mind that while you'll no longer be subject to termination in this particular case, that won't help when someone using your app switches to another app and then later comes back to your app. If you don't implement state restoration, that common use case will not work correctly.