Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle MainActivity destruction on Android (like retrieveLostData of ImagePicker) #1258

Open
MilesAdamson opened this issue Apr 11, 2023 · 9 comments
Assignees
Labels
android Issue applies to Android platform feature-candidate This issue might result in a feature to be implemented help wanted Extra attention is needed high priority High priority issue suggestion New feature or request

Comments

@MilesAdamson
Copy link

MilesAdamson commented Apr 11, 2023

Issue

When an Android device is low on memory, or for whatever reason the OS chooses, the MainActivity can be destroyed when the file picker is opened. When the user returns to the app, the file they selected is lost. This is more likely to happen on weaker devices, and with phones that very aggressively kill activities to save battery (Samsung).

It is possible to restore the user to the screen they last were in with flutter's built in RestorationScope, but it's not possible to grab the file they picked. This can put users in a loop where they then try again to pick the same file, MainActivity is killed, the resume where they were without the file picked, and so on. Making it impossible to pick the file.

Related, but they all get automatically closed
#1170
#733

Steps to reproduce

  • Turn on developer mode
  • Turn "Don't keep activities" on in the developer options (or use a piece of crap Samsung device that is relatively low on memory)
  • Open flutter app
  • Select a file
  • OS now kills the MainActivity
  • When you re-enter your app, whether the screen is restored or not, the selected file is lost

How this is handled with ImagePicker:

Future<void> getLostData() async {
  final ImagePicker picker = ImagePicker();
  final LostDataResponse response = await picker.retrieveLostData();
  if (response.isEmpty) {
    return;
  }
  final List<XFile>? files = response.files;
  if (files != null) {
    _handleLostFiles(files);
  } else {
    _handleError(response.exception);
  }
}
@MilesAdamson MilesAdamson added the suggestion New feature or request label Apr 11, 2023
@MilesAdamson MilesAdamson changed the title Handle MainActivity destruction on Android (like getLostData of ImagePicker) Handle MainActivity destruction on Android (like retrieveLostData of ImagePicker) Apr 11, 2023
@philenius philenius added the android Issue applies to Android platform label Apr 12, 2023
@philenius
Copy link
Collaborator

@MilesAdamson, you're welcome to contribute to this repo. Miguel is too busy 😉

@github-actions
Copy link

This issue is stale because it has been open for 14 days with no activity.

@github-actions github-actions bot added the stale label Apr 20, 2023
@MilesAdamson
Copy link
Author

Sorry I don't think I can add this feature for you

@philenius philenius added feature-candidate This issue might result in a feature to be implemented and removed stale labels Apr 21, 2023
@khjde1207
Copy link

Any workaround?
Cannot select file due to Destruction of MainActivity on Galaxy Note 8.

@MilesAdamson
Copy link
Author

MilesAdamson commented Jun 9, 2023

Not that I know of. Users are not able to pick files on certain tablets in my app either

@azizarc88
Copy link

someone already try to add that feature, but no response anymore
#488

@Pluxury
Copy link

Pluxury commented Jan 22, 2024

Are there any updates on this topic? Why did the author just close this 488 ?

@miguelpruivo
Copy link
Owner

Sorry — I've been a bit away from the project so I'm trying to catch'all the missing stuff. Is this an issue as of today? Would #488 fix it?

@miguelpruivo miguelpruivo self-assigned this Mar 20, 2024
@miguelpruivo miguelpruivo added high priority High priority issue help wanted Extra attention is needed labels Mar 20, 2024
@MilesAdamson
Copy link
Author

This is still in the same state as when I created the issue. From what I can tell that PR would solve it yes but I didn't test out his branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issue applies to Android platform feature-candidate This issue might result in a feature to be implemented help wanted Extra attention is needed high priority High priority issue suggestion New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants