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

Fix using SharedPreferences in overriden onDeleted method for Android #184

Closed
wants to merge 3 commits into from

Conversation

Codestian
Copy link

Allows the ability to create unique key values for each widget instance, based on widgetId.
The onDeleted method is needed to clear orphaned keys when the widget is deleted from home screen.
Example on usage is provided.

@ABausG
Copy link
Owner

ABausG commented Dec 2, 2023

Can you link to some official Android Documentation where this is coming from and why it is necessary?

@Codestian
Copy link
Author

I am unable to find a specific android documentation that mentions this, but I found this which details what remove does.

It seems to be an industry practice to clear key values which are not used, to prevent unnecessary storage from building up. In this context, when a home widget requires multiple key values that are unique to itself (such as title and image file path), the key values must be named along with its widget id. So when the user discards the widget, onDelete is called and the key values can be discarded. This pull request enables the shared preferences to be used on the onDelete method.

If all home widgets share the same key values with no id attached, some widgets will be overwritten with the new values when the user decides to configure individually (which refreshes all the widgets) or when the device is restarted.

Providing onDelete with shared preferences would also allow Flutter devs more options on what to do with the key stores when the widget is deleted from homescreen.

@ABausG
Copy link
Owner

ABausG commented Dec 3, 2023

Hmmm, so I think a nicer way would actually be to do a callback back to the flutter side, to remove the values from there as that would be the place where values would be written so it makes more sense in my opinion to also delete the data from the Flutter side of things

@ABausG
Copy link
Owner

ABausG commented Mar 5, 2024

Closing this for now as I think as the Flutter App is adding the entries the Flutter App should also be in charge of removing them again. Let me know if you are strongly opposed to this

@ABausG ABausG closed this Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants