Open Source • Background Tasks: Itoo 🚀

Following to the received suggestions, I eventually succeeded in building a working app.
I believe worthwhile to post my example app about a basic usage of Itoo and MelonNotification, that I am going to exploit for another real project and that I hope could turn out to be useful for somebody else.

ItooProjectExample.aia (154.5 KB)

Any comment is welcome.
Thank you, Taifun and Kumaraswamy!

1 Like

To stop the service you could just call Itoo1.StopService in the StopButton.Click event without using a broadcast

Also you do not need this

the MelonNotification.AskPermission methoid is already doing it

Taifun

1 Like

Hello Taifun, thank you for the advices.
Actually, to stop the service, I followed the guidelines and recommendations of background music player showcase project (Detailed guide for creating a background music player with #Itoo).

In your case, you can simply directly call StopService in the StopButton click.

1 Like

Hello, it works as it should... on the Samsung tablet. However, on the Motorola device itoo does not close down completely.

Going to the setup screen I use 'StopProcess'. Afer coming back 'ProcessRunning' even notices itoo is not running
anymore it starts again after loading the new settings.
But, after that, on the Motorola device the timer (starts web.get) does that twice in the normal time, while broadcasting the interval shows the correct time.
When I go to setup again and come back the timers fires 3 times in that time.
Again... everything runs perfectly on the Samsung device.

A reboot of the device or reinstall of the app is necessary to get the proper timing again. Is that a known bug with Motorola (or even more brands)?
Any tips to prevent that from happening?

A picture with the most important blocks. And also the aia.

Thanks,
David


p1_Monitor.aia (600.0 KB)

Hi, I'm on break due to my exams until Feb 24.

Hello, good luck with your exam!

If anyone else wants to test too... this much simpler example replicates the error: Every time after stopping and starting itoo the counter is incremented 1x extra every 5s. The Motorola device runs on Android 14. The Samsung tablet where the problem does not occur runs on Android 10.


itoo_test_1.aia (108.2 KB)

Hello,
Thank you for your suggestions, here below my example app sorted out accordingly:

Unfortunately, even though I set MelonNotification AlertOnce property to true, each time I am going to update the notification message in the Clock Timer event, notification alert sound keeps triggering and it is quite annoying.
How can I make the notification silent or, at least, make it trigger the alert only the first time?
Thank you all.

try to set it in the BackgroundClock event handler
Taifun

1 Like

If you're working with background processes, this guide lays out the essentials really well! Running tasks smoothly while an app isn't active can be tricky, but frameworks like this make it easier. Also, for those managing projects and resources, having the right tools to store and organize data efficiently is key! :rocket:

Hello @vhDavid

After restarting the Itoo process (using StopProcess and then CreateProcess) you are telling me that every 5 secs the count is updated twice?

Could you please post an example (a quick screen recording)?

Yes that's right. But in my case that is not a problem, because I turn off my mobile phone every evening. Your exam is much more important. Here is the screen recording.

I had some pretty interesting results on my Android 14 as well, the behavior of services seems to have changed.

I observed that when you stop a service, then restart it, the service then does not begin with a new memory, it rather reuses old stuff.... I will work on this when I have some time. Thank you for the report.

Had some time this evening :grin:

I am trying Itoo for the first time and I am unable to get it working. I am testing the sample project "PropertyCatcher" and there is a runtime error.


I am using the version 4.4 of the extension. Anyone can suggest how can get it working?
I tried testing it on Android phone by building the apk. The apk installs but then I get to see only a blank screen and the screen gets unresponsive. I have to close the app manually.

Itoo does not work in the companion app
Build your project and test usung the apk file

Which Android version are you using for your tests?
Does the accelerometer sensor work, if you try a simple example project in the foreground?

Example project: App Inventor Code Snippets | Pura Vida Apps

Taifun

I tested the accelerometer in foreground and it works.
I am using Android 14.

What exactly do you expect the example to do?
It does not much, see again the documentation

The above example demonstrates how properties Sensitivity and Minimum Interval for the Accelerometer Component is saved and reapplied in the background.

You probably like to do something else? What exactly?

Taifun

I have a question.
I am converting my app to service running in background by Itoo extension.
My app includes two Clock components that I have already rearranged to trigger in background by RegisterEvent. Now I have this event too, that is triggered continuously by one of background Clocks:

Unfortunately my app does not work, then I figured the reason out: I forgot to transform this Event block also to make it trigger in background, as per Kumaraswamy's guidelines. But such Event includes a parameter (text read from file): how I would be supposed to convert it to background event? All examples I have seen do not include any parameter in the Events used.
Thanks in advance for any help.

the event handler you have to create must have the same number of arguments, in this case the argument text

Taifun

I really need for help.
After applying last Taifun's suggestion (thank you again, Taifun), I just finished converting my app to background service. Unfortunately, my app is not fully working. Long story short, my app continuously checks and fetches a file generated by another app and containing the working time marks (ins and outs), in order to calculate my working time spent and show it in a notification message. Here below the blocks of my app:

As core of my app, there are 3 events triggering in background (highlighted in yellow):

  • one main Clock Timer, that sets the rate of check and read of time marks file
  • the read file Event, in charge of times calculation (including a check when it is time to stop the background service)
  • a secondary Clock Timer, for a delayed stop of the background process.

Since the size of my app is quite big, I highlighted (in red) also the sections to focus and concerning my problem. Background process stopping action can occur in 3 ways:

  • by pressing the button in the interface of the app
  • by pressing the button in the notification message
  • programmatically, when - based on times calculation - my app decides that the moment has come to stop the background service

The malfunction is related to the buttons (in the app interface and in the notification message): when pressed, the service does not stop, but it keeps running. On the other hand, programmatical stop of the background service works like a charm.
I post here a video of my app showing the problem (the app visible at the beginning of the videoclip is that one producing the working time marks file):

Any help will be very welcome and appreciated. Thanks in advance.