Periodic "unauthorized access to" on Android FMX App

Periodic "unauthorized access to" on Android FMX App

Postby scottlynn » Wed 26 Apr 2017 12:55


I am developing a Delphi FMX game on Android. I have a TLiteConnection and some TLiteQuery's in a TDataModule accessing a sqlite database file that I create and store in my app's user folder. Which on at least one device is:


App is being written in Delphi 10 Seattle. Anyway, everything seems to be working great. I have no LiveBinding controls connected to the queries. Everything is being accessed through code, and rather minimally as well.

Every now and then, when going to the home screen and then switching back to the app, I get the error message listed below, that I have an unauthorized access to "". But then the database stuff still works great right afterwards. Is there something I should be doing on deactivate to get rid of this message? Thanks.

Exact error message:
Detected problems with the app native libraries (please consult log for detail): unauthorized access to ""

Posts: 4
Joined: Thu 08 Dec 2016 17:46

Re: Periodic "unauthorized access to" on Android FMX App

Postby scottlynn » Mon 01 May 2017 14:23

No answer yet, and I was digging around looking for ways to handle the OnFormSaveState event, so here is what I am trying so far. It is an intermittent error message, so it will take a couple days of testing to determine if I have this fixed. I am trying to close the database connection in OnFormSaveState and then opening it again when my form is reactivated in Android, which requires adding an App event handler and registering it. If anyone else wants to try this, here is the code required to do it.

1) You need to add FMX.Platform to your uses clause.

2) You need something like the following in your OnCreate

aFMXApplicationEventService: IFMXApplicationEventService;
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService)) then

3) Declare the following as a procedure in the public declaration of your form:

function HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;

4) In OnFormSaveState close your database connection

5) Make sure your OpenDatabase routine is smart enough to check if it is already open or add a force open flag. Because it will be called once on program restore, but twice during a normal program startup.

6) Here is my HandleAppEvent. I have some extra comments that records the order of events I encountered while testing different restore scenarios. Enjoy. Note I am not doing anything on WillTerminate since I already handle those things in OnFormClose.

function TFormMain.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
case AAppEvent of
TApplicationEvent.aeBecameActive :
// AddLogEvent('TAppEvent.aeBecameActive');
// Reconnect to database if not connected
Result := true;
TApplicationEvent.aeWillTerminate :
// AddLogEvent('TAppEvent.aeWillTerminate');

// Have seen these
// TApplicationEvent.aeWillBecomeInactive : AddLogEvent('TAppEvent.aeWillBecomeActive');
// TApplicationEvent.aeEnteredBackground : AddLogEvent('TAppEvent.aeEnteredBackground');
// TApplicationEvent.aeWillBecomeForeground : AddLogEvent('TAppEvent.aeWillBecomeForeground');
// TApplicationEvent.aeFinishedLaunching : AddLogEvent('TAppEvent.aeFinishedLaunching');

// Haven't seen these yet
// TApplicationEvent.aeLowMemory : AddLogEvent('TAppEvent.aeLowMemory');
// TApplicationEvent.aeTimeChange : AddLogEvent('TAppEvent.aeTimeChange');
// TApplicationEvent.aeOpenURL : AddLogEvent('TAppEvent.aeOpenURL');

// Startup sequence --> OnCreate, OnShow, OnActivate, aeFinishingLaunching, aeBecameActive

// Here is the order for a Home screen and then fast switching back to app
// aeEnteredBackground, OnFormSaveState, [fast switch to app], aeWillBecomeForeground, aeBecameActive

// Here is the order for a screen lock (dark) and then wakeup and unlock and app restore
// aeEnteredBackground, OnFormSaveState, [screen off then on], aeWillBecomeActive, aeWillBecomeForeground, aeBecameActive
Posts: 4
Joined: Thu 08 Dec 2016 17:46

Re: Periodic "unauthorized access to" on Android FMX App

Postby scottlynn » Mon 01 May 2017 20:39


It still fails with the same error message. If I fast switch in Android to another app or click to Home screen then fast switch back into my app, I get "unauthorized access to". And the only database code that has even run since app startup is:

OpenDatabase call from OnShow:

if (TFile.Exists(FormMain.sPathToDatabase)) then begin
SQLC.Database := FormMain.sPathToDatabase;

And then the following executes in OnFormSaveState:

if qryGeneral.Active then qryGeneral.Close;
if qryVerseList.Active then qryVerseList.Close;
if qryVerseText.Active then qryVerseText.Close;
if SQLC.Connected then SQLC.Disconnect;

Then I switch out and come back into the app and get the error about unauthorized access. Any help appreciated. Not sure what I could be doing wrong at this point. Trying to figure out how to view the log that is mentioned in the error.

My research so far points to a bug in Android 7 Nougat, and that is the only device that has shown the message in my testing.

Someone else posted the following in a forum for a different development platform:

"In Android 7.0, the low-level Sqlite binary can no longer be used by apps. If you use one of the portable Sqlite libraries for .NET (like sqlite-net or Iridium), you will get the warning. Most libraries will be updated to use the "Android-approved" way of accessing Sqlite on the device." Further down in the same post, someone gives instructions on upgrading package libraries, but I am not sure how that will help my deployment issues. The bug sounds like it is understood and a fix is in the rollout phase.

- Scott
Posts: 4
Joined: Thu 08 Dec 2016 17:46

Re: Periodic "unauthorized access to" on Android FMX App

Postby MaximG » Mon 15 May 2017 07:46

According to the description this problem occurs only when using Android 7 Nougat and is not directly related to LiteDAC behavior. You can test the work of the developing application using the Direct Mode : when working with SQLite DB does not require any external libraries.
Devart Team
Posts: 792
Joined: Mon 06 Jul 2015 11:34

Return to SQLite Data Access Components