Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
7
Erster Beitrag:
vor 4 Jahren, 7 Monaten
Letzter Beitrag:
vor 4 Jahren, 7 Monaten
Beteiligte Autoren:
Paul Murray, Ruben Sanchez Peña, DerekT

WDM 18 - TimerSys Problem

Startbeitrag von Paul Murray am 31.05.2013 06:44

Greetings All,

From what I have read in the help I have an expectation that I can run a procedure every two minutes that will collect GPS data from the Android device and sent it to my server using a web service that I created.

The procedure to send the GPS data works fine if I call it by clicking on a button.

But I cannot get the procedure to run automatically using TimerSys. Here is the code that I am running in the Initialization Code of for the Android Project:


GPSInitParameter(gpsAuto, gpsPrecisionHigh + gpsSpeed + gpsEnergyMedium)

gnTimer_number is int

//TimerSys(GeoProcedure,12000)
//gnTimer_number = TimerSys(GeoProcedure,12000,1)
gnTimer_number = TimerSys(COL_GlobalProcedures.GeoProcedure,12000,1)


And here is the code in GeoProcedure:


PROCEDURE GeoProcedure()
MyPosition = GPSGetPosition()
grLatitude = MyPosition..Latitude
grLongitude = MyPosition..Longitude
// Speed
IF MyPosition..SpeedValid = True THEN
grSpeed = MyPosition..Speed
ELSE
grSpeed = -1
END

Info("MyPosition is",grLatitude,grLongitude,Now)

grBatteryPercent = -1

//Get the datetime the measurement was taken
gdtGPSLocalDateTime = MyPosition..MeasurementDate
//Get the precision or quality
IF MyPosition..PrecisionValid = True THEN
grPrecision = MyPosition..Precision
END

WHEN EXCEPTION IN
sl is add_gps_data
sl.password = "xxxxxxxxxx"
sl.latitude = grLatitude
sl.longitude = grLongitude
sl.battery_percent = grBatteryPercent
sl.quality = "*"
sl.imei = gsIMEI
sl.speed = grSpeed
sl.device_date_time = gdtGPSLocalDateTime
sl.gps_app_transmitter_version = "A1.0"
rp1 is add_gps_dataResponse
rp1 = add_gps_data(sl)
Info(rp1.add_gps_dataResult)
DO
Error(ExceptionInfo(errFullDetails))
END

IF rp1.add_gps_dataResult "" THEN
Info("Sorry. There was a problem Sending GPS Data in the Global Procedure GeoProcedure.")
END

Info("timer running")

gsStatus_type = ""


Anyway, the code in the above procedure works fine if I call it from a button. But TimerSys does not seem to work on my Samsung 10.2 Device.

If anyone can offer some suggestions, I would really appreciate it.

Thanks!!

Paul

Antworten:

Paul
Try changing this to an 'automatic procedure'
Click on the (small) 1:30 icon, top right of the code editor
See the help under 'automatic procedure' for more info

von DerekT - am 31.05.2013 07:28
Thanks Derek,

I saw your previous post on this subject and tried it.

I got the message that it was not supported in WDM 18.

Paul

von Paul Murray - am 31.05.2013 17:12
Hi. In Android you can't execute threads or timers when the application is running in background. If you need run a code in backgroud you must use a Service. In WM18 you must use a "Persistent Thread" to simulate a Service. It will run when your application go to backgroud also.


Rubén

von Ruben Sanchez Peña - am 31.05.2013 22:13
Hi Ruben,

Thanks very much for your help.

I have the timer running now only because I associated it with the window.

But as you mentioned, it will probably not run in the background.

Can you kindly share some sample code as to how I would get my GeoProcedure to run in the background and please let me know where I should put that code?

Thank you!!

Paul

von Paul Murray - am 31.05.2013 22:31
Greetings All,

I put the following code in my Window intialization event:


gnTimer_number = TimerSys(COL_GlobalProcedures.GeoProcedure,12000,1)


I deployed the App and I see that the GPS data is hitting my server every two minutes.

Then I pressed the HOME button and I opened Safari.

I spent 20 minutes using Safari and it appears that my App continues to connect to my web service and send GPS data.

Is this correct? Would it not do this if I ran another App?

Any info will be appreciated.

Thanks!!

Paul

von Paul Murray - am 31.05.2013 23:31
Hi. A "Normal" application running in background can be killed by Android or by an application memory optimizer when the phone need more memory for run another application. With the new WM18 "Persistent Thread" feature, the applications isn't killed, or if the application is killed it is launched again.


Rubén

von Ruben Sanchez Peña - am 01.06.2013 11:32
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.