Open Source โ€ข Background Tasks: Itoo ๐Ÿš€

Well, there are so many examples available in this thread...

see also what Gemini is responding below
Taifun


In MIT App Inventor, an argument in a procedure is a variable that receives a value when the procedure is called. It acts as a placeholder for data that you want the procedure to use to perform its task.

Key Concepts

  • Parameter vs. Argument: The terms are often used interchangeably, but there's a technical distinction. In App Inventor, the variable defined in the procedure block is a parameter. The value or variable you provide when you call that procedure is the argument.
  • Input for Procedures: Arguments allow you to make a procedure more flexible and reusable. Instead of creating a separate procedure for every slightly different task (e.g., one to calculate the area of a 5x5 square and another for a 6x6 square), you can create a single procedure that accepts the side length as an argument.
  • Scope: The argument variable is local to the procedure. This means it can only be used and its value can only be accessed within the blocks of that specific procedure. It doesn't exist outside of it.

Example
Imagine you want to create a procedure that calculates the area of a rectangle.

  • Without Arguments: You would have to hard-code the length and width inside the procedure.
    This procedure would only ever calculate the area of a 10x20 rectangle. It's not reusable.
  • With Arguments: You create a procedure with two arguments, length and width.
    Now, when you call this procedure, you provide the actual length and width values.
    When you call the procedure and provide the values 5 and 8, the length argument receives the value 5 and the width argument receives the value 8, and the procedure then calculates 5 \times 8 = 40.
    This single procedure can now calculate the area for any rectangle you specify, making your code more efficient and organized.


I have understood the explanation.
Getting back to original code above:
bgTimer does not have any parameters, so no arguments.
But MyFGprocess also does not have any parameters, then why x argument there ??

Also, in the image provided by you, process "run" does not have any parameters, then why x argument there?

From the Usage documentation in the first post here

This is a requirement for iToo to work correctly.

Also to play a sound, see again the already given advice

Taifun

Screenshot 2025-09-16 223826
So, while I was making an app designed to detect movement and then send a notification to the phone, I realized that the code did not happen more than once. I wanted to know if it is possible to start the entire code from the movement detection until the notification once again? This is all I did for the looping function and I don't really get how to do it.. if it is possible... Thanks.

How do you loop an entire system using Itoo extension?

Screenshot 2025-09-16 223826
So, while I was making an app designed to detect movement and then send a notification to the phone, I realized that the code did not happen more than once. I wanted to know if it is possible to start the entire code from the movement detection until the notification once again? This is all I did for the looping function and I don't really get how to do it.. if it is possible... Thanks.

Create the process for example in a button click event. . The name of the procedure should be loopingfunc

Then do what you want to do regularly in the event handler called loop

How do you do this?

Taifun

So, the idea is for the detector to detect movement while the app is closed until the user decides to stop it, so I was hoping for it to continue performing its processes everytime it detects movement. However, when I tested it, it tests for movement once, does all its procedures once, and doesn't do it again. For reference it starts from here:
Screenshot 2025-09-17 071927
After it senses shaking, it does this:


Which in short, just tests for movement every 500ms until it hits 5 times in which it will then activate the next procedure:

This builds and sends the notification and it is here where I try to implement the loop. So, I do want to try the button thing you said.. but wouldn't that only loop it when the button is pressed? I did try it but I still don't know what I'm doing... this notification has extra buttons which send a message when pressed btw. Don't know if thats needed but yeah.

Hi,

I'm trying to save a list in Itoo but it doesn't seem to show anything in the list. Any ideas ?

You are currently saving an empty list in your code.first fill a list,then save it

1 Like

@SlowBro There is a lot of confusion in your blocks, it looks like you are putting blocks together without understanding what you are doing

Have you seem my shake it example? Run app in background, that fires an alarm whenever phone is shaking - #4 by Taifun

Use that example and restart from there
You create the process only once on button click

It starts the background process... somehow the process must start...and after starting the process then the sensor is activated to listen in the background

Taifun

@Jimis your blocks are mostly ok, you are adding item "1" to the list, you only forgot to store the new list via StoreProperty method again, so later you see the difference after button click in the user interface... don't forget to open the listview there

Also there is no user interface in the background
EDIT: what you are doing is no real background processing, you are only creating the process, so this is not really a test if something is working in the background or not...

Taifun

Thanks !

Oh I see, thank you, I was following an example from a different discussion. If I may ask as well, can itoo fetch a local variable in other procedures from another procedure if it is stored in itoo? Thanks.

Use StoreProperty/FetchProperty methods
Taifun

1 Like

Trying To Show Latitude & Longitude Why Showing 0 0

Because at the time you are creating the process you did not get a gps signal

Also what is localhost124?

Generally to get location data in the background requires background licatuon permission. The locationservice extension is able to do it App Inventor Extensions: Location Service | Pura Vida Apps

Taifun

Can you elaborate on this?
What would you expect to happen?
Status is always unknown because unknown is a static text in your procedure

EDIT: do you expect to get both evemts twice (one from the background, the other from the foreground?
what do you get if you deactivate the 2 phone call events (foreground)?

For a more useful test let me suggest to do a background test, close the app and use the Notifier Loginfo method for debgging and check the log using logcat

Taifun

Thank you for you helpful comments and questions - And I am sorry that I just noticed your post yesterday :frowning:

First of all, I apologize for this sloppy example/case. It was based on a test case that contained two Player components: one in the UI and another in the Itoo process. I suppose I was attempting to show that the UI Player PhoneCall events responded to a phone call but the Itoo events did not...

I would have expected the PhoneCall events that were registered in the Itoo process to respond to the call and not the UI built-in blocks...however because of how it actually behaved (the UI built-in events responded in place of the itoo registered events, it was confusing..

Yes - another sloppy job on my part... Because the text block "Join" would not accept the "status" variable, rather than solving that problem, I just put in the "constant" value... I have now decoded status using this procdure/function:

The version I am posting below is (hopefully) more useful and easier to understand.

ItooMusic_orig_PhoneCall_posted2.aia (4.2 MB)

...and the blocks:

I have done separate tests for both of these variations. In all tests the app was started, then the player started, then a phone call was made but not answered - caller hangs up. Here is a brief description and summary of results.:

  1. With both sets of events present in the code (as posted here), logcat was captured for two cases:
    a) UI remained active/visible: the UI event blocks responded to the call/hang-up:
    ItooMusic_orig_PhoneCall_posted2-UIactive-both.txt (490 Bytes)
    b) UI was exited: no PhoneCall event was called:
    ItooMusic_orig_PhoneCall_posted2-exitUI-both.txt (147 Bytes)
  2. With the standard PhoneCall event blocks disabled in the UI/foreground code, logcat was captured for two cases but no PhoneCall events were called in either case:
    a) One with the UI remaining active:
    ItooMusic_orig_PhoneCall_posted2-UIactive-X.txt (228 Bytes)
    and
    b) the other having exited the UI:
    ItooMusic_orig_PhoneCall_posted2-exitUI-X.txt (228 Bytes)

It appears that somehow the Itoo registered events are not being associated with the player running in the Itoo process - they are not called in any of the test...OR perhaps the player is not actually running in the Itoo process???

Are the process/thread ids from the logcat output of any use in determining this? Any test I can do to gather more information?

-Randal

the PhoneCall component was not written to be running while the app is in the background...
as you can see the phone state listener will be unregistered while closing the app, see the sources here appinventor-sources/appinventor/components/src/com/google/appinventor/components/runtime/PhoneCall.java at master ยท mit-cml/appinventor-sources ยท GitHub

@Override
  public void onDestroy() {
    unregisterCallStateMonitor();
  }

let me invite you to test my new phone state listener extension which keeps running while the app is in the background... I will send you a PM soon...

Taifun