Android Question [SOLVED] Weird File.Exists behavior

Computersmith64

Well-Known Member
Licensed User
Longtime User
Must be my day for weird crap...

I have the following sub that checks whether an options file exists, then if it doesn't (so it's a new install) it does one thing & if it does (it's an update) it does something else.

B4X:
Public Sub Read_Options() As Boolean
    If File.Exists(File.DirInternal, "options.dat") Then
        mOptions = File.ReadMap2(File.DirInternal, "options.dat", mOptions)
        Return True
    Else
        Return False
    End If
End Sub

I have used this sub in virtually every app I've written & it has worked fine, however today I came across a strange behavior on a device running Android 8.1...

If I uninstall the app from the device (including for all users), then reinstall it from B4A, the first time it runs File.Exists returns true - & the version data in the options file shows the previously installed version (proving that the file is actually there). If I then completely kill the app, then run it again, File.Exists returns false!

I don't understand. Is there something weird with Android 8.1 where the app isn't fully uninstalled?

- Colin.
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
It's very strange. What's even weirder is that if I install v1.4 of the app from Play Store, then uninstall it, then install a debug version (still v1.4) from B4A, the "options.dat" file that gets loaded says that the previous installed version was 1.3.

Looks like I'll have to keep digging...

- Colin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Can it be that fileexists is returning true for something like "options.dat.old" or even "options.dat.bak"?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
It's very strange. What's even weirder is that if I install v1.4 of the app from Play Store, then uninstall it, then install a debug version (still v1.4) from B4A, the "options.dat" file that gets loaded says that the previous installed version was 1.3.

Looks like I'll have to keep digging...

- Colin.
Did you run the Google play installed version at least one time before uninstalling?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Can it be that fileexists is returning true for something like "options.dat.old" or even "options.dat.bak"?
No - I just ran a File.ListFiles(File.DirInternal) & then logged the resulting list & "options.dat" is there even after an uninstall...

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Did you run the Google play installed version at least one time before uninstalling?
Yes - didn't make any difference. It's like it has cached the previous install files & then is somehow using them instead of the new install.

- Colin.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Have you tried another writable folder just for testing? It may be related to those new "enforced" permissions
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
This is what I get on the first run after a fresh install:

(ArrayList) [firebase_inter_process_mutex-lock_send_report_to_server.lock, firebase_inter_process_mutex-lock_write_report_to_sqlite.lock, .Fabric, options.dat, virtual_assets]
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Can you reproduce it on a small project?
Your logs show firebase related stuff, can that be the base issue?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Can you reproduce it on a small project?
Your logs show firebase related stuff, can that be the base issue?
I haven't been able to reproduce it, so it appears to be related to this particular app (I think). I'll try one of my other older apps that uses the same setup & see if I have the issue.

- Colin.
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Having same issue with Android 8.1.
Try this:
Uninstall app, turn off internet connection and then install it again without internet connection.
It's look like google make Internal folder backup (cloud probably), when you install app again, all files in internal folder are on their place (restored from backup).
You can also change package name.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Having same issue with Android 8.1.
Try this:
Uninstall app, turn off internet connection and then install it again without internet connection.
It's look like google make Internal folder backup (cloud probably), when you install app again, all files in internal folder are on their place (restored from backup).
You can also change package name.
Yep - that was the problem. Spent half of last night trying to figure it out, but had forgotten about Android cloud backup - DOH!

Thanks Pendrush!

- Colin.
 
Upvote 0
Top