Open Source • Background Tasks: Itoo 🚀

Right, but it is recommended to use the Firebase Database REST API alternatively to the firebase component for background services.

You can achieve the same functionality through the API.

1 Like

Thanks for the help, certainly the code seems better now, I receive a message that the app is in background -which is good-, but I struggle to receive the data from the database while in background.
Following the lead from Kumaraswamy, I am doing it with the REST API, but I go back to the same problem, I can not check the value from my database with the library.

Thanks in advance!

1 Like

You should add an argument called "x" to the procedure "Check".

Then you should register an event called "Clock2.Timer", providing a procedure callback, from where you will do the get request.

Like this:

1 Like

@Kumaraswamy, the problem with StopProcess still exists... Even if I stop the process from inside.
Please, look. Here my blocks from my working example:

I'm compairing value of the variable from TinyDB. When process starts, it become equal to "0".
But, when app starting again and Screen1.Initialize, it changed to 1. After that Notification of Taifun's location service disappeared, icon of the Foreground service disappeared too, but Notification from the background task continue appear every 1 second. And it shows that process does not running!

It continue to appear from 1 to 10 minutes, or sometimes even more, I restarted my phone and do not know, how long it would appear. Is it possible to fix it?

UPD. Ok, this one works:
Снимок экрана от 2023-06-18 13-59-56

It stops the task completely after 2nd iteration.
But, as for me, it's complicated a little and implicit. To stop the process and task immediately as for me, this one the only solution - to do such "if" condition.

Hi, I believe this is something to do with the comparing results.

As per your edit, i understand that it's working fine after adding "if" condition, let me know if something is not right yet.

Hi, I have been testing the comments you did yesterday, but with no luck.


I am just trying to make a sound whenever the callstate variable is equal to 1. But it is not being triggered.

I will describe what I expect to happen because perhaps I misunderstand the background service and perhaps I need the foreground one:
-Once the user closes the app (with the home button only), the database has to be continuously checked to search for a change in a certain variable (callstate).
-If callstate is equal to 1, it has to trigger a sound (simulating that you are receiving a call).
-If the callstate is equal to 0, it has to stop the sound (just in case it was being played before).

Later, once this works, I will try to use one more timer to make it sound continuously.

Thanks in advance!

PD: perhaps the error is in the web URL that I introduced? I want to access OnGoingCall variable:
image
And in the database it looks like:
image
It should be giving the result of ongoingcall, right?

1 Like

Hi, yes you should start a foreground service instead in your case, replace the url with another simple example url, then after the got text procedure is triggered, for verification, send a notification to alert (for testing purpose), after you are sure the web functionality is working, replace the urls with the real ones.

If you want to get periodic event, don't forget to call Clock component in this way (evaluate but ignore result):

I would like to use Itoo to ping an API and, depending on the result, send a notification about it. These blocks are not working:


Can I not use the Web1.GotText handler with Itoo?

No, you can't do this directly
Read the complete Itoo thread to find several examples how to do it

Taifun

2 Likes

You have to registeer the Web1.GotText event with necessary arguments included in the procedure from where you will handle the response.

Ohh, so I need to use two Itoo1.RegisterEvent blocks, one for the timer and one for the web component? Or do I need to do something else with the register block?

1 Like

That should work fine.

Okay! I'll try it and see.

1 Like

What was the result, so far?

What do I put for procedure?
Web1.GotText did not work and I think leaving it empty would cause a runtime error.

Here is one of several examples of a got_text procedure which can be found in this thread

Taifun

1 Like

You have to put there a procedure name that will be called, it will have the same values as the Web1.GotText event:

1 Like

Still not receiving any notifications from the NotificationStyle extension :thinking:.

It does not make sense to set the responseContent parameter like this...

First get something simple running, for example periodically send a notification. After you got that running successfully then try again a more complex example

Taifun

3 Likes