Open Source • Background Tasks: Itoo 🚀

I have just tracked down one of my programming errors which turned out to be the use of a built in Color component block where a hexadecimal number for a color was expected in a block that was being executed by an the event registered by:

events

This error of mine became obvious when I executed the same (or similar) block from the foreground portion of the app - it was clearly reported by the system when it occurred.

My question is: Is it possible to gain insight into such errors when executed in the background?

Could the Screen1.ErrorOccurred event be made to fire? Possibly by registering it with itoo1.RegisterEvent?

How about the error log? Could anything be written to the error log and viewed by "adb.exe logcat"?

Is there some way to connect (AI Companion, Emulator, USB) and debug such an app? My app foreground process closes immediately after it creates the background task. If I kept it running would background errors such as this be reported to the UI?

Any suggestions besides "don't write buggy code"? :slight_smile:

Kind regards,
-Randal

I'll possibly work on a better feature to report errors, (after two months, my exams get over).
The only way to debug right now is to check the logcat.


Itoo does not support companion debugging, even if it is someway implemented to mimic the functionality, we cannot afford its code maintainability.


So there is some kind of error happening... Did you try to use ADB to check for the error logcat? If you are able to capture it through ADB, you can send it personally to me. Most of the times errors happen when components are not initialzed or set properly...

Thank you for addressing my general and specific question.

That would seem to be a very useful enhancement. After a while, since users could see their own errors displayed, you might recover your time spent developing the capability because you would get fewer questions about problems we might be having :slight_smile:

Yes, I did. But I never was able to locate anything in the log. If you think it should have been there, then I can re-run the buggy version and try again.

Do you have any suggestions as to "adb.exe logcat" options that might eliminate entries that would not be of interest? perhaps piping to "grep XXXX".

As I mentioned, I found the error after I ran the same type buggy blocks (I had used a color when a hex number for a color was required.) in a foreground portion of the app - the error was reported to the phone screen.

I will see if I can build a small test case that exemplifies the error and then see if I can locate the error using logcat. This would be good practice for locating future bugs.

Kind regards and good luck on exams, :student: :+1:

Randal

1 Like

therefore the general advice is to first get it running in the foreground...

did you check logcat? you might find something using the tag "ItooCreator"...

you should find something using logcat...

Taifun

1 Like

Great extension with it any application made with app inventor can work in the background.

I see that there is doubt about how the extension works, I am attaching two aia files, which can help you understand how it works.

One is a step counting app that works in the background, so it will always count your steps.

Another is an Alarm manager

Both work correctly, although as usually happens, the battery mode must be set to "No restrictions" for them to work correctly on lame Xiaomi or Samsung phones.

two requests to the developer

First, the notification can be interacted within the service to change the title and subtitle and when you click on it, the activity opens with the NEW_TASK flag.

Another option is to create a kind of static procedure in the main activity that can be used in the service, so that the number of blocks can be removed from it.

AlarmaItoo.aia (164.3 KB)

ServicioIto.aia (126.3 KB)

1 Like

WOW I LOVE IT!!! That's incredible what you have done with Itoo, especially the Pedometer one, can you please publish them as a guide (a new topic) so that it could help others?


I dont get the second request, what does it mean?

Indeed I did!

Here are the blocks. The offending one its the passing of a built-in Color where a hexidecimal color number is expected (color Red)

logcat, soon after "##################", contained the following:

01-27 23:15:24.522 30979 30979 W System.err: java.lang.IllegalArgumentException: Unknown color

The logcat context is included below. (BackGndErr_dies-logcat.txt)

As I get more familiar with the format of these errors, I should be able to "grep" them out of logcat output.... Looks like a good first cut would be:

adb.exe logcat | grep "System.err"

I am a little surprised that it is only a "W" and not an "E" category, so that tells me to examine all entries, not just those of the Error category.

Thanks for your help!

Kind regards,
Randal

BackGndErr_dies-logcat.txt (3.9 KB)

Can you tell us where does the block "IbpAllAlarms.HexToColor" come from? Also you are passing a color to a block when it expects hexadecimal value (something like #845EC2)... So the error is obvious...

1 Like

I'm glad you like the .aia files, I'll get back to the tutorials and I'll publish them as a separate thread as you tell me.

You like the pedometer but I think the Alarm one is more complete, because the same service opens or closes automatically, whether or not it has pending alarms.

As for my second request, like you I program some extensions (the notification that I use in the .aia is an extension that I am creating pending perfection) and you know that procedures can be shared between the main activity (or main class) and the service if these procedures are static

For example

Main class

package es.mariosoft.PedometerService;

procedure

static String GetValue(String tag, String default) {
SharedPreferences settings = context.getSharedPreferences("MarioPedometer", Context.MODE_PRIVATE);
return settings.getString(tag, default);
}

Service

package es.mariosoft.PedometerService.Service;

@Override
public void onSensorChanged(SensorEvent event) {
goal = Integer.parseInt(PedometerService.GetValue("PedometerService.goal", "10000"));
weight = Integer.parseInt(PedometerService.GetValue("PedometerService.weight", "65"));
stepnotice = Integer.parseInt(PedometerService.GetValue("PedometerService.notice", "1000"));

As you see I am using a procedure created in the main class in the service.

I think it would be interesting to implement something similar to this in your extension since it would help the blocks within the service not be so extensive.

Un saludo

Oh, so basically you want reverse of what the extension does? Like do you want to be able to call application's procedures from a background service? Also, it's better if we continue the discussion through PM.

Greetings, dear Kumaraswamy!
I wrote in this topic an application on your extension for remote temperature measurement: BLE_WEATHER_V1.2.aia
Now the task is to register coordinates in the background based on LocationSensor.
But, the sensor hides when the application is minimized, although this does not happen in Google Maps!
You once wrote that some sensors are blocked in the background. But there are a lot of videos on the Internet about implementing background tracking. They talk about using Java. So is this possible?
Can you add this feature to your extension?
So far I have limited myself only to the ability to reduce the screen brightness to a minimum and disable all on-screen buttons and the map...
Best regards!

Hi @Jerej, the location sensor is not supported in the background, this has to do with the missing manifest elements of the application.

In the newer versions of Android, directly querying location in background without special permission/access is not supported.


Itoo right now only supports what it can in the background, I do not plan to add any extra features into the extension meanwhile.

At the moment, Itoo is a pure implementation of only background processing capability.

For alternatives solution, you may explore these extensions:

Well! And thanks for that! I'll definitely check out the recommended apps!

1 Like

I have planned to integrate Itoo functionality into the locationservice extension, this then enables us to execute almost any task in the background using Itoo (however no user interface components).

In case you are interested in sponsoring the update and get access to the beta version to test, please send me a PM... How to send a PM (personal message)

Taifun

2 Likes

Yes, it is a rename of SimpleToast.HexToColor - [Free Open Source] my toast extension 3.0

In earlier efforts I had used the hex color value to adjust a color to match a certain background on the phone I was using. When I "reused" the code I wrongly substituted a color block for the hex value :frowning:

Thank you for your help. For me, it was doubly helpful since I was forced to learn how to locate System errors in logcat output :slight_smile:

Kind regards,
Randal

2 Likes

Help i cant get the variable text to clouddb.
I did try with save file also didnt save the text varisble

The Clock1.Timer event handler should be called timer without arguments to not get confused...
In there you read the file

And register additionally the File1.GotText event using the argument text
In there you use your Cloud db block

Taifun

I just remove and place the readfile blok to timer but still no data send

Still confuse
I just need to send file content to cloud in background

I did that but still no data send
I replace cloud db to save file for easier to check the data

I did this but the data only sending (saving) when the app is restarted

If you want to read the file on each Timer event, then you should read it in your event handler for the Timer event, which is your procedure lokal

Your path of your file method does not make sense... why are you using that path, which points to the companion app? You can test only after building the app anyway

And why did you change the example again? Your original plan was to store something in CloudDB?

Taifun