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

no, when I close all apps, the notifications on the screen are turned off.

Can you please send me a short screen recording of that happening? You can message me privately by clicking on my profile.

Hi, @Kumaraswamy , I created an app that plays sound when new order is received as notification in our phone.

blocks (12)

Now it is time to include Itoo extension as well. Can you give some tips?

My Plan: To create an app that gives continuous alarm sound whenever new-order-notification-email is received in phone. I am using ecwid.com to sell products online, so whenever new order is placed by customers, Ecwid will send new email notification about the order to me.

Give me some tips to use Itoo extension more efficiently in this app. Thankyou.

Okay, since you've got that working normally in background, here's what you can do to turn it into a background mechanism.

  1. DONT start directly, first play around with the Itoo extension with some examples you may find in this topic.
  2. After you are a bit familiar with the Itoo extension (first you must know how the extension works before you actually directly use it) then you can start converting your blocks into background functions to work with Itoo.

After only you have tried something and get stuck (not knowing what to do) you can ask for help here.

1 Like

Okay.

your solution does not really work, see also my answer here Is it possible to make an app that notifies me with alarm sound when I get new mail from specicific email id? - #22 by Taifun

Taifun

1 Like

I am just learning about itoo, and I have a few more questions:

The first regards clarification (and a possible suggestion) regarding the RegisterEvent block...

  • Register events
    events
    • eventName: component name and event name combined, like Clock1.Timer.
    • procedure: procedure called when the event is invoked with the args.

I was having trouble until I named my app's "procedure" to be called on the event occurrence to be the same name as the name of the event. For example in the case of eventName: "Clock1.Timer", the procedure: must be "Timer". If that is true, perhaps this be further explained in the extension description. While I noted that this is the way it is done in the example, it did not occur to me that it was necessary :frowning:

[Actually, if this IS the case, could you just eliminate the "procedure" parameter altogether and get it internally by parsing the eventName parameter?]

The second question regards the itoo DB vs. the standard Tiny DB component.

FetchProperty

StoreProperty

  • They are like Tiny DBs of Itoo, these blocks can be used in the background services, especially for non-foreground services to store and fetch properties. They provide special connectivity between services and and the application realtime.

Besides the convenience of having data items closely associated with its itto object, what is the advantage of using it (FetchProperty/StoreProperty) vs. using a separate Tiny DB? Can't a regular Tiny DB be used in non-foreground services? Isn't it available to both the app foreground and non-foreground threads/processes?

Kind regards,
Randal

This is not true, you can use any name, but the arguments must be the same as the original event... The Clock1.Timer event does not have any arguments but for example the Web1.GotText event has 4 arguments

TinyDB relies on SharedPreferences, this causes synchronization issues. That means when a value is updated from the App, it doesn't necessarily mean the changes will reflect in the background process.

To solve this issue, Itoo offers a Store/Read functionality similar to TinyDB to combat this issue

Taifun

1 Like

Thanks for taking time to answer.

:frowning: as you knew, I had other problems ... I have now happily renamed my Timer procedure to TimerEventProcessing :slight_smile:

Thank-you for the explanation. I was trying to reuse some TinyDB code segments. I shall switch to itoo's FetchProperty/StoreProperty DB facility.

-Randal

1 Like

... if I may ask one more related question:

Is a global variable that is written by a foreground app available to the background process? And vice-versa: is a global variable written from the background available to the foreground? Subject to synchronization? Where could I read things like this about foreground vs. background processes and their interaction / communication?

-Kind regards,
Randal

No, use the StorePropeety/FetchProperty blocks
Taifun

1 Like

Ok ... I really did not think I was asking the same question! But I guess I did :frowning:

... thanks for your patience.

Kind regards,
Randal

It's okay to ask questions.

Well, that's good because I have plenty :slight_smile:

As I read this and other threads, I have become quite confused about background vs foreground processes/tasks/threads.

In your example, "Notification Every Second":

I assume there is a process, "P0", which executes the Button1.Click event, correct? Is it fg or bg? When does it terminate? It would seem to continue, with screen1 being "active" and visible.

Does the Button1.Click event create (via itto1.CreateProcess) a background or foreground process, call it "P1", which then executes procedure "clock"?

Does "P1" run to completion after registering the Clock1.Timer event?

What/which process executes the "timer" procedure when the Clock1.Timer event fires?

I think I will stop there for now.

I should add that this is not just of academic interest. I am aware that some things cannot be done from a background process (or an inactive process - what's the difference. Oops, there's another question:-) . For example, I find that a Notify1.ShowAlert will work from places where a toast ( [Free Open Source] my toast extension 3.0 ) does not - or perhaps there are other problems with my tests that lead me to conclude this.

Kind regards,
Randal

This is not a process it is the main activity of the app, see also Introduction to Activities in Android - GeeksforGeeks

The answer is here in post 46

See also again the definitions in post 1

Itoo supports two types of services.

  • Foreground
    • keeps the service alive throughout the session without interruptions.
    • a permanent notification will be displayed throughout the session from Oreo.
  • Background Task
    • unlike the foreground task, it is executed on a different process.
    • vulnerable to unexpected / sudden shutdown by the system (especially Samsung, Xiaomi devices).
    • the running task should be completed within 10 or 30 minutes depending on the Phone brand.
    • it is possible to restart the service from then, by setting the restart property to true

Taifun

1 Like

After registering nothing is running

Itoo will take care of it
Don't worry too much about how it is working... it is a piece of magic by @Kumaraswamy :wink:

Taifun

1 Like

Also regarding the Notifier1.ShowAlert, they are UI interactions that do not always work on across all devices, so I wouldnt recommend touching them in Itoo.

Well, clearly, this is not something I am going to understand ... so I may as well "believe in magic":slight_smile:

So now, I must let you see my app and get some help.

I want to alert the user with something like a toast or Notifier1.ShowAlert when cell data has been left on and/or is actually being used (under some circumstances, configurable by the user).

The toast I am using does not work from the background timer event processing (I figured there is a reason for this that has to do with bg/fg), but Notifier1.ShowAlert seems to be working, so I was counting on using it. Then I am advised:

So, am I going to have to give up on displaying a brief message on top of the active app and just use a notification to alert the user?

-Randal

So far I have only tested this on android 8.0, but I would like it to work up through 14.

DataMinder_toastCase.aia (902.8 KB)

Hi, if the Notifier1.ShowAlert works for you, then you may use it, but it may be inconsistent across devices. You may alternatively show a notification to the user instead:

Thanks for the clarification. I will plan to use both ShowAlert and a notification.

I have already imported the modified Notification Style (see in my blocks the calls to Has/Ask permission blocks)

Thanks again for the interaction/help.

Kind regards,
Randal

[20240125 edit]
I tried the DataMinder_toastCase test app on a Pixel running Android 12 and the toast worked! but the Notifier1.ShowAlert did not :slight_smile: So, I think I will start out with all three mechanisms, emphasize the NotificationStyle notification, but also include the ShowAlert and toast. I can allow the user to select the methods which work on his device and disable the others.

1 Like