I have a problem with one of my apps. When I open my app and just go through it. close it with my home button of the phone and reopen the app I get an access violation at address
error. This error only appears on code where the component TMSFMXCheckGroup is used. Now I have some ideas to solve it but don't know if they are good and works.
Just fully close the app when the app closes via the home button so the app opens next time with a clear cache.
I want to empty all CheckGroups so only the checkgroups start fresh.
when the app closes via the home button next time you open it begins on the home page of the app.
I don't know if one of these solutions works and how I implement this in my code.
If there is another solution that's better let me know!
Thanks in advance for all the help.
I've looked at the other questions and the answers but with no result. The solutions they had didn't work for me because my app is on ios and android so I need a solution for both.
To react on the home button under android you can implement a Application Event Handler and react on WillBecomeInactive or WillBecomeForeground to return to the home screen of your app. I use this method to save my data when entering background to prevent data loss when an App is closed while in background.
The Event Handler is installed using
IF TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(AppEventSvc)) THEN
AppEventSvc.SetApplicationEventHandler(HandleAppEvent);
in your forms oncreate method. The Event handler itself could look like the following:
FUNCTION Tmainform.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
BEGIN
IF (AAppEvent = TApplicationEvent.EnteredBackground) OR (AAppEvent = TApplicationEvent.WillBecomeInactive) THEN
BEGIN
// do any action here;
END
ELSE IF (AAppEvent = TApplicationEvent.WillBecomeForeground) THEN
BEGIN
// do any action here;
END;
END;
I would go for the WillBecomeForeground in your case.