Open Source β€’ Background Tasks: Itoo πŸš€

The CallBackgroundProcedure is only meant to be called from the user interface (non background), it wont have any effect if you do so from background.


Yes! The naming convention ui_ just tells Itoo that the procedure must be executed on the user interface. (Note: if the application isnt active, the procedure wont get executed). You can also normally use the ui_ procedure.


It will be true since now you are in the background.


Now it will return false, since the flow is not in the background anymore.


It is the same as when X called ui_Y, it will be false.


Now again the application flow is in background, so it will be true!

Thanks for very clear answers! It all sounds very manageable.

Only one more question occurs to me at this point: Is there a call that the itoo background process can make to determine if the UI is active?

-Randal

Hmm maybe there are such features offered by Android, but with the current version you cannot do it directly.

You can create your own methods, for e.g. you can implement any of these:

  • Heartbeat timer: Update a value every X second in UI and check the last updated time in the background.
  • Echo method: Send a message from Background -> UI, and make the UI send back a response to the message. If the background receives response in given time, then it concludes the UI is active / inactive.

You may expect this feature officially added in the upcoming updates.

Kumaraswamy,

Thanks for the information... and two great ideas if it is necessary. But as I understand it, making the mistake of calling ui_xxxxxx from itoo background would not do anything (and therefore, not anything bad :slight_smile: )

I also intend to use the implicit event registration you have provided in this update - another nice touch!

BTW, may I ask what "itoo" means or represents (a word? an achronym?)

[Edit about 4am GMT Wed]
Came across another question:

How can UI get a function return from a background component. For example, if Player1 is running in a bg itoo service, how can the UI determine the value of Player1.Is_Playing or Player1.Source?

Any method other than the above "echo method" in reverse?: UI procedure X calls bg procedure Y that makes the inquiry (Player1.IsPlaying) and sets an itoo variable which is monitored (loop or alarm) by the UI X for an updated value....?

Randal

Calling ui_x does something, it calls the procedure from the UI. (If the UI is active)


Yeah I didnt include it in the first post to not confuse new users :wink:


It is just a random name I come up with sometimes, I guess its cool to pronounce "Itoo" :grin: (o in Itoo is pronounced as English letter O itself)


You are right, there is no direct way to do it exactly, I just got an idea to take the extension two steps further in future. For now you need to either "ask" the background service to provide that information in some way using the existing communication tools (procedure calls, itoo's store/fetch) etc.

I would say In the coming months, the future of creating background tasks, is gonna be more revolutionary. It could also be possible in theory to "directly interact" with background components from UI :wink:


To solve a similar problem, a few months ago I was working on bidirectional streaming communication system. That would provide seamless communication b/w the background and the UI. Couldnt do a lot of work back then.

I'm not aware of anymore other non-similar methods, but the future of development of this extension is going to be aimed towards solving those kinds of issue.

Hi @Kumaraswamy,

I found a problem with the latest Itoo extension 4.4. Took me a lot of time to figure out what the problem was. My phone is Android 14 Xiaomi Redmi note 12 Pro.

The problem is that if you use 2 screens, let's say the 1st screen is a welcome screen and use Itoo extension in the 2nd screen, then you have to add Itoo extension in the 1st screen also (photo) else the Itoo process won't start in the 2nd screen !

I added a test file.

Itoo_test_error.aia (3.4 MB)

Your app works for me, tested on Android 11 and Android 14.

Perhaps it might be your device optimisation? See here: Xiaomi | Don’t kill my app!
App Settings -> Enable AutoStart

Can you confirm if it works for you if you start on Screen1 and the issue is with other screens?

PS: I'm working on a new extension that would replace Notification Style (may take around a week, after my exams)

1 Like

Hi,
Did you delete the Itoo extension from the 1st screen (photo) ? If you try the file as is it will work

You also need to uninstall the app before installing it

If I use Screen1 only it works ok

The problem has been noted and will be fixed in the next update.

Thanks!

And good luck with the exams :slight_smile:

2 Likes

I should have said :frowning:

Thanks for the discussion/answers - it helps....and the future of itoo looks bright!

Why do I keep thinking of "just one more question" :-?)

Ok - last one, I promise (until I think of another :slight_smile: )

Once the Itoo.StoreProperty is used, when does the itoo data space get cleared. When it is stopped using Itoo.StopProcess? How about when it is forced to terminate using "Force Stop" in settings? Would it ever be necessary to uninstall in order to clear the data space?

Kind regards,
Randal

PS Someone mentioned your exams. When? Good luck!

1 Like

Hi, I need help with programming in MIT App. I am using the Itoo and UrsPahoMqttClient extensions. I need to create a notification when an MQTT message is received. If I close the app (not just send it to the background), the notification stops working. I tried using a timer or something similar, and it works the same way. Is this even possible? Can someone explain this to me? Is it because of TinyDB?

Yes it would be necessary to uninstall in order to wipe clean entire data.


They are already here, Thanks :smile:

There are a couple of things you are doing wrong.

  1. Yes, do NOT use TinyDB, alternatively you should use Itoo's own Fetch/Store blocks

  2. Secondly, in the pozadhi procedure, you are not touching any block of MqttClient so therefore, that component will not get created at all!

    blocks(37)
    Just add the above block at the start of pozadhi

  3. Thirdly, you are registering the events wrong! Anyways, if you are on the latest version of extension, you can use automatic events feature (you wouldnt need to use the RegisterEvent block) Just do this:

    In this procedure, you will handle the message received event.

  4. Fourthly, you CANNOT interact with UI blocks from the background. That means you wont be able to change any Label's text, any such attempts may crash the app.

  5. You cannot use Global variables in background.

Reading the first post, about design and guidelines will help you.

Thanks, I am trying it.

Well I guess that would be the primero example of "persistent" data :slight_smile: ...

BTW, on this app I am using a home spun method of keeping up with what's in the itoo data. I have wrapped itoo.StoreProperty with a procedure which first fetches a list variable, propertyList, from itoo (empty one if not there), checks to see if the variable being stored exists, and if not, it then adds it to the list (which is also stored in itoo). So that I can dump the content of the itoo memory variables at any time for debugging or whatever. Not sure it will be worth the trouble, but I am trying it. [this reminds me I must disallow the name of the list as a variable to be stored - oops :grin:]

Thanks,
Randal

1 Like

Hi, I tried to change code but the function the same. Please help me.

I said you to make a procedure like above and use that for the message event.

And what is with procedure when MqttClient.MessageReceived?

Go through the examples in the first post, you'll get to know.