[Discontinued] Background Tasks [4.1] 🥳

I am very happy to hear that :blush:

1 Like

In the TimeOut property, what could be the maximum value?

7000 is the default value?

There isnt any maximum value about that.

My procedure has worked correctly, but I’m not sure how the foregroud service works.

Once this TimeOut has been reached, is the process killed and automatically restarted?

My phone is xiaomi and it has many restrictions, every x time the service closes and starts again, but it is not a defined time, it is random.

I will have to do tests on other devices.

When the timeout is reached the service is killed.

Not sure about the random thing, can you explain it mroe?

A simple example that shows a notification on every data change event.

Since the extension has the LoadTemplate feature, we can use that. The template template.txt is located in the assets directory.

template's content
t.create("com.google.appinventor.components.runtime.FirebaseDB", val0);
t.invoke("set-firebase-default-url-dynamic", val0, "DefaultURL", new String[] {val1});
t.invoke("set-firebase-normal-url-dynamic", val0, "FirebaseURL", new String[] {val1});
t.invoke("set-firebase-token-api-key-dynamic", val0, "FirebaseToken", new String[] {val2});
t.invoke("initialize-firebase-database", val0, "Initialize", null);

24.11.2021_13.55.46_REC

In the designer properties, you should check the “Repeated” value and set “RepeatedType” to High. This will force the restart of the service intensely when stopped.


There may be some little problems while using the restarted properties, when the service is restarted the values are updated so the notification may trigger again. Setting a project bucket manually should make the situation better.


DataBase.aia (461.7 KB)

3 Likes

Good evening.

Background Tasks [4.0]
Take a look at the blocks:

Xiaomi phone - Android 5.1 (API 22) MIUI
Xiaomi phone - Android 6.0 (API 23) MIUI

Not working - app shuts down after start of task.

Xiaomi Phone - Android 8.1 (API 27) MIUI

Works, but after closing the app completely, it stops.

Phone on Android 11 not MIUI - works as it should.

Am I doing something wrong?

Hi, if you are using foreground mode in Android below 7, because of a bug, that wont start.

If the application crashes, it maybe a different issue, you can PM me the APK or AIA.

MIUI requires autostart permission to run in the background in case you clear the app from recents.

2 Likes

hey, did you set the app to no restrictions under energy option

2 Likes

Also, If you are using foreground mode, you dont need to create those blocks, alternatively you could just call a procedure that will do that easily.

2 Likes

Yes i set, if I don’t disable energy saver,
the task is performed, but then MIUI turns it off. (this is on android 8.1)

The project you sent me is working on Android 11 just fine.

1 Like

Yes it works on Android 11.
But on Android 5.1 and 6.0 the app crashes after starting a task when the Clock1.Timer event occurs.

So far on Android 7, there isnt any issues, I will check on others.

2 Likes

The issue has been tracked.

The extension is built with Java 8 sources. Some features arent available on older devices since they run older versions of Java. This should be fixed in the next 4.1 update.

4 Likes

How can we filter this? So how do we make it work for a value?

You use firebase bucket property.

1 Like

@Xoma i want to call a procedure how can i ?

Have a look here.

1 Like

Hi everyone , just wondering if its just me but when I set my url for firebase , automatically is added “developers” in it …

Let’s say iI programmed that every time data changed save something in FBdatabase in GPS/ with tag “Location” and value “lon”,“lat”…

well, the result is that it saves in GPS/ with tag Locationdevelopers and value “lon”,“lat”…

thank you if someone know how to fix it