Open Source • Background Tasks: Itoo 🚀

Which means, you are using an older Android device

What about elaborating, what exactly you are planning to do in the background?

Taifun

I want to receive data via bluethooth. When the right data is received sending a notification.

Yes, you can do that, use CreateProcess. This requires to show a persistent notification, which can be dismissed through a simple swipe (starting from Android14).

There already have been some Bluetooth examples here in this thread Search results for 'Bluetooth order:latest' - MIT App Inventor Community

Taifun

I would like to better understand what this means especially as regards accessing the same named clock component from both UI and by the service started by itoo1.CreateProcess, specifying procedure for example as "PlayerService". I hope answers to these questions will help.

  1. If I have a clock named clkWallClockTime is it proper to reference it both from the UI or the itoo service by the following?

  2. If I have a clock named clkDelayStart which is referenced in PlayerService by:
    clkDelayStart.Timer_Interval = 1000,
    ...then can I enable that timer from Screen1.Initialize by:
    clkDelayStart.Timer_Enabled = false?
    [Edited 0514 GMT, 8 May, 2025]

  3. If I define the event processing in the clkDelayStart.Timer event from the UI AND in the itoo service using itoo1.RegisterEvent (clkDelayStart_Timer) from PlayerService with procedure such as "eventProcessing"...then when the timer fires, which will be executed: the UI defined event processing or procedure "eventProcessing" registered by PlayerService or both?
    [Edited 0514 GMT, 8 May, 2025]

I hope these make sense, even though I know I am asking them out of my confusion :frowning:

Kind regards,
Randal

This means before creating an event handler for a component do something with that component
For example for a clock set the time interval

Alternatively just add an evaluate but ignore block together with the clock in your CreateProcess procedure

Yes you can
You could take the the current time from any clock, no separate clock necessary

First set the time interval and to enable the clock set TimerEnabled to true

The UI event will get triggered only if the app is in the foreground

Only one event will get processed depending on the app being in the foreground or background
I'm not sure, if both will be executed in the foreground... better to test this or wait for an answer from @Kumaraswamy
EDIT: see my test below Open Source • Background Tasks: Itoo 🚀 - #1041 by Taifun

Taifun

Taifun,

Thanks for your thoughtful replies... this helps.

I do not want to make CallBackgroundProcedure or ui_wrapper calls unnecessarily to call between UI and itoo service, if I can just reference the one Clock from both.

The general question is "can I set/get properties from a single Clock both from the UI and the itoo service (so long as I reference the Clock in the CreateProcess procedure)?"

I do not think this is something I would ever want to depend on, but it would help (at least help my understandind :slight_smile: ) to know. I can imagine that if the UI is in the foreground/active when the timer fires that there may be no way to predict which "event" is ahead in some queue. So @Kumaraswamy, if there is no answer :thinking:, I understand.

Thanks again,
Randal

Are these usage rules meant only for components, blocks, and procedures accessed and executing from/in the itoo service?

[I ask because, while I am making extensive use of the itoo store/fetch property facility, I am also using TinyDB but from/in the UI only.]

If that is the case, is it permissible to use global variables if they are only accessed from/in the UI?

-Randal

Yes of course
Taifun

Good! I had misunderstood this...
Thanks,
Randal

Does the same apply (direct access of a single component from UI and itoo service) for a Player component as it does for a Clock?

For some reason I have been under the impression that when a Player is referenced within the itoo CreateProcess procedure, that a distinct and different Player is "instantiated" - one which is separate and independent of the one which exists in the UI - which can must (and may only) be accessed from the itoo service.

So that, in order to interface with a single Player from both UI and the itoo service, one must call a ui_ prefixed procedure from the itoo service or call an itoo CallBackgroundProcedure from the UI (or use a messaging mechanism) in order to control a single Player, which exists only in either the UI or in the itoo service.

Is this correct? Or, for example, can a single UI Player component be referenced directly from the itoo service as well as being referenced from the UI (the way a Clock component can)?

-Randal

To understand what is happening it is advisable to create a test project... I did it for you below

There is a Clock1 running in the foreground and a Clock1 running in the background running independently from each other

The counter in the foreground works only if the app is in the foreground. Timer interval is 5 seconds. After closing the app it starts from 0 again.

The counter in the background starts after clicking Start button. It increments each 2 seconds being the app in the foreground or in the background. In case the app is in the foreground, the current background counter value will be displayed in a label.

randall.aia (94.1 KB)

Taifun

1 Like

Well, how very kind of you to do this for me!!...

Let me study and play with it for a bit...

THANK-YOU,
Randal

1 Like

Indeed - two instances of Clock1, one in the UI space and the other in the itoo (background) service space.

Just to confirm the complete separation of the two clocks "address" space, I added reading and displaying the interval and enabled properties before they were set in both spaces.

What I found for the Itoo Clock1 was surprising. Before procedure "run" set the properties, they were not according to the initial values given in the "Designer" view which were 1500 msec and false, but were 1000 msecs and true.

Not a real problem, since initializing them in run is sensible and probably good practice, not counting on any design initial values. But it was surprising.

As far as the question about Player components, I realized that the app discussed in post #808 demonstrates the independence of Player components with the same name in both UI and Itoo service environments.

Thanks for your help me sort this out.

Kind regards,
Randal

1 Like

can anyone help please i don't know what's wrong but it does not work for me.
i get the itoo notification that the process is working on the background but i don't get any notification from Melon, when i click Button2 the notification appear. but with itoo not working when the app killed

You need to add a variable x to your doBackgroundWork procedure.

2 Likes

just adding it will make it work ? i will try and see

And yes it worked thanks for the help mate :heart:

1 Like

@Kumaraswamy,

I want to be sure I have the latest itoo version...

I downloaded it from the link at the end of this initial itoo post and installed it...I expected the info to show "Sky 4.4.1"

itoo-20250302-440sky

The file size on windows is 93,033 bytes.

Is this the latest version? (4.4.1?)

Kind regards,
Randal

Yes, it is the latest version (built on march 2nd). I have likely forget to bump the extension version.

:+1:Thanks,
-Randal

1 Like