Android Question Starter service loosing variables initialization?

FrankBerra

Active Member
Licensed User
Longtime User
Hi all,
i developed an application that seems working good almost on all devices, but an user has a lot of problems with it.
He sent me a screenshot with am error saying that a "Object should be initialized (Map)" but that the Map is initialized in Starter service.

I am wondering if there can be something that interfere with the normal lifecyle of the starter service, or if the starter service can be killed in background while the app is opened and in that case it loses all references to variables....or something else!
Any suggestions?

The variables in starter service are declared/initialized like this:
B4X:
Sub Process_Globals
Dim MappaEtichette As Map
End Sub

Sub Service_Create
MappaEtichette.Initialize
MappaEtichette = File.ReadMap(File.DirAssets, "etichette-it.txt")
End Sub

Thanks in advance!
 

johndb

Active Member
Licensed User
Longtime User
What is the device model and OS version of the device having this problem?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Move the code to Service_Start.
I'm not sure if this will work for you, but try the code below a try. Is this the only Map in the service?
B4X:
Sub Service_Start(StartingIntent As Intent)
     If Not(MappaEtichette.IsInitialized) then
          MappaEtichette.Initialize
          MappaEtichette = File.ReadMap(File.DirAssets, "etichette-it.txt")
     End If
End Sub
 
Last edited:
Upvote 0

Grant Fullen

Member
Licensed User

Agreed. You're going to want to use the built in debugging or print a bunch of log messages to find out which map *SPECIFICALLY* isn't being initialized.
Log(myMap)

It'll be null or undefined or something like that in the Log window.
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Thanks all for the tips!
On all my devices the app works perfectly without errors.
But apparently on some others it is not working due to unknown behaviours.

The device of the user seems to be a Galaxy S2 but i developed the app also on that device! So it is strange!

Sometimes the user says that he don't get any error but when he try to login nothing happens, like other variables aren't initialized or he removed some authorizations like read/write or internet access. But sometimes he say that the app works for a while.

In all this mess the very strange fact is that the Map it is not initialized and it should be because it is initialized in service start!
Does anyone know if the system can't read "etichette-it.txt" from asset folder deinitialize also the Map?
 
Upvote 0

Grant Fullen

Member
Licensed User
It'd just crash if you use File.ReadMap and it can't find the file, as opposed to saying the map isn't initialized. Is that the only Map variable you have in your entire app?
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Ok thanks but the problem there is not if i should initilalize or not before reading the file. The problem is that the Map initialized for sure in starter service is seen as NOT initialized in another activity that is using that map.
There are others objects/strings/things initialized in starter service but that map it is the only map used in the first activity when you open the app for the first time.

Is it possible that OS or Task killers destroy ONLY starter service so the other activities loose variable initialization?
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Yes i know but the app creshes at the first anomaly that occours. This is a smartphone of a user living hundreds kilometers away and i can't debug with his device so i can't test if other things aren't initialized
 
Upvote 0

Grant Fullen

Member
Licensed User
If you already know why it's crashing then why are you asking here? I mean we've given you guidance on how to debug. When it comes to runtime errors, it could be a huge number of things that don't make sense at first. Claiming there are other maps in your app but you know this is the one crashing...... that's just countering what we're trying to tell you.
 
Upvote 0

Grant Fullen

Member
Licensed User
Yes i know but the app creshes at the first anomaly that occours. This is a smartphone of a user living hundreds kilometers away and i can't debug with his device so i can't test if other things aren't initialized

And how do you know this is the specific anomaly? You don't. You need to debug and find out. If they're that far away then you should release an update that saves any exceptions to a log file and have them send it.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I am not sure but it could be a antivirus or any other task killer that will kill background activities to save memory.
my s8 has a build in app that does it. that could be it but I may be wrong
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I am not sure but it could be a antivirus or any other task killer that will kill background activities to save memory.
The error is thrown by an activity, which tries to use a variable (map) declared as public and initialized in the Starter service; you should kill the whole process to "delete" that map.

CTRL+F to search the name of the map (MappaEtichette) and I think you will find a line with MappaEtichette instead of Starter.MappaEtichette.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User

This should be the behavior but a service is a running activity and if you kill it the public variables of it wont be accessable any more and you have lot of apps that sell you stories by saying they will make your phone faster and what they do is they kill all background activities. So if the starter service was killed the reference to the map will not exists anymore.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…