Author Topic: Running background tasks  (Read 3966 times)

MobileGuy

  • Newbie
  • *
  • Posts: 5
Running background tasks
« on: July 16, 2011, 07:24:22 AM »
On the home page its states that Hac can run background tasks but there doesn’t appear to be any info about running a background task or setting one up.

Can the current version of Hac run background servcies like those described here:-
http://stackoverflow.com/questions/3067324/android-run-in-background-service-vs-standard-java-class

I'm not clear about Android background tasks in general and whether they keep running when the app has been sent to the background or are they they are like iPhone apps where the app effectively  pauses when in the background?

Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 287
Re: Running background tasks
« Reply #1 on: July 16, 2011, 07:57:26 AM »
On the home page its states that Hac can run background tasks but there doesn’t appear to be any info about running a background task or setting one up.

I'm sorry about this lack of info.
Apps built with HAC can run either in the foreground or background.


Can the current version of Hac run background servcies like those described here:-
http://stackoverflow.com/questions/3067324/android-run-in-background-service-vs-standard-java-class
HAC built apps are more like the traditional apps seen on desktop and laptop computers. When sent to the background the app keeps running its scripts so the app designer doesn't have to make a separate background service. Of course when in the background the app doesn't receive input via the screen or keyboard but it can still keep working when needed. It can receive data from the internet, process files and data etc.


I'm not clear about Android background tasks in general and whether they keep running when the app has been sent to the background or are they they are like iPhone apps where the app effectively  pauses when in the background?
Yes, in general Android apps can keep running in the background and it doesn't matter whether they are a java service as you mentioned above or an app built with HAC.


I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

MobileGuy

  • Newbie
  • *
  • Posts: 5
Re: Running background tasks
« Reply #2 on: July 16, 2011, 10:49:38 AM »
So can an app created by Hac have several services running at once or is it limited to one service?

When a Hac app is in the background will its timers keep running or will they pause until it moves to the foreground again? The Guide section mentions timers but some example code would be really helpful to clarify things.

Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 287
Re: Running background tasks
« Reply #3 on: July 16, 2011, 11:22:21 AM »
So can an app created by Hac have several services running at once or is it limited to one service?
A HAC app has only one thread for executing its scripts but can launch helper tasks such as when downloading a file/page from the web.
The script thread is event driven so events caused by controls , timers etc are added to the event queue. Its possible to use a timer, or timers to give the illusion of multiple scripts running at once.



When a Hac app is in the background will its timers keep running or will they pause until it moves to the foreground again? The Guide section mentions timers but some example code would be really helpful to clarify things.
Timers will keep running when the app is in the background.

Here is a very basic example showing how to use a timer, and that the timer doesn't pause when the app goes to the background. All it does is increment a counter once per second and put it into a field - - it needs 2 buttons, 1 field and 1 card timer-


Start Button script:-
Code: [Select]
Global countVar

Reset countVar

Put countVar into field 1

TimerSet(1,2,1000)


Stop Button script:-
Code: [Select]
TimerOff(1)



Card Timer script:-
Code: [Select]
Global countVar

Increment countVar

Put countVar into field 1

I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

MobileGuy

  • Newbie
  • *
  • Posts: 5
Re: Running background tasks
« Reply #4 on: July 18, 2011, 01:46:18 PM »
Finally installed Hac after installing Java and Android stuff then tried some projects on my Hero phone. They all worked fine although now I need to understand how they actually work as I'm new to programming.

I tried your code above and it ran fine with the counter running even when in the background  :)