Android Question application cache - Solved

alon

Active Member
Licensed User
Longtime User
Hi All ,

I am working with mqtt, and after a while
I am not getting any massages, and the Logger.LogCatStart also stops from writing any logs to my file.

Now if I will go to app manager and clear the app cache, everything start to work fine.

is there a way to clear the app cache from myapp , or maybe other solution that I do for that problem?




Thanks
 

drgottjr

Expert
Licensed User
Longtime User
whether or not clearing the cache is actually the solution is unclear, but if you absolutely must do it from the app, you can try this code:

B4X:
Log("trying to clear cache")
jo.InitializeContext
Dim appmanager As JavaObject
appmanager = jo.RunMethodJO("getSystemService",Array("activity")).RunMethod("clearApplicationUserData",Null)


but you need to know:
"(the command) permits an application to erase its own data from disk. This is equivalent to the user choosing to clear
the app's data from within the device settings UI. It erases all dynamic data associated with the app -- its private data
and data in its private area on external storage -- but does not remove the installed application itself, nor any OBB files.
It also revokes all runtime permissions that the app has acquired, clears all notifications and removes all Uri grants
related to this application." don't say you weren't told.

you also need to know that the command kills the app. don't say you weren't told.s o there is no way to know from within
the app if the command has been successful. presumably, if you re-launch the app, it was successful. presumably, you could
also check the app's storage and cache before issuing the command and then having a look afterwards.

since the command kills the app (with no notice), you'll have some explaining to do to your users.
 
Upvote 0

alon

Active Member
Licensed User
Longtime User
whether or not clearing the cache is actually the solution is unclear, but if you absolutely must do it from the app, you can try this code:

B4X:
Log("trying to clear cache")
jo.InitializeContext
Dim appmanager As JavaObject
appmanager = jo.RunMethodJO("getSystemService",Array("activity")).RunMethod("clearApplicationUserData",Null)


but you need to know:
"(the command) permits an application to erase its own data from disk. This is equivalent to the user choosing to clear
the app's data from within the device settings UI. It erases all dynamic data associated with the app -- its private data
and data in its private area on external storage -- but does not remove the installed application itself, nor any OBB files.
It also revokes all runtime permissions that the app has acquired, clears all notifications and removes all Uri grants
related to this application." don't say you weren't told.

you also need to know that the command kills the app. don't say you weren't told.s o there is no way to know from within
the app if the command has been successful. presumably, if you re-launch the app, it was successful. presumably, you could
also check the app's storage and cache before issuing the command and then having a look afterwards.

since the command kills the app (with no notice), you'll have some explaining to do to your users.
I will try that.

but can you pls tel me what type of an object is jo?
jo.InitializeContext

Thanks
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
java object.
 
Upvote 0
Top