[Discontinued] Background Tasks [4.1] 🥳

Could you try using the normal notification component?
Are you using notification style extension?
If it did not work, PM me the AIA.

thank you i will try it

1 Like

im only seeing notifier components please where is the Notication truly i cant find it

Hmm… if to use the notification component (normal) then you have to account → settings → enable experimentally.

And this may be creating an invalid function error in the background…

i have send the aia
thank you

1 Like

Extension Guide and Q/A

These are some of the points that you have to know to correctly use the extension.

  • ExtraFunction

    • Extra function is same as the regular function block (CreateFunction). ExtraFunction block was added because of lack of ability to compare things or objects or the same as IF ELSE blocks. This was added in version 3.1, follow this post and be aware of changes in version 3.2 of this post.
  • FinishTask

    11.07.2021_10.52.38_REC

    • FinishTask block (above) is called in the background/foreground service. This is like a task to be done in the service and not called from outside.
  • Intrepert and MakeExtra

    • You will find two blocks that can interpret the Java statements and return the result. Interpret block just directly returns the value (outside service) and MakeExtra will return the value (not interpret result) that will be executed in the service.
  • MakeDelay

    • Block will freeze or put the service into sleep mode for the given number of seconds. This will also pause any ongoing operations. This block has no effect on the UI of the application.
  • CreateComponentsOnUi

    • If this property block is set to true, components will be created on the normal thread of the application. Most of the components like Firebase, clock, pedometer, Bluetooth must be created on the UI thread. Creating on this thread will need more time for the components to be created.
  • How to work with foreground

    • Foreground is mostly used for components like the player or other components to continuously stream from the service. From Android 7 and above, there will be a notification of the set configurations (i.e title, subtitle…)
  • Making it easy

    • It really makes confusing while using the extension when you just have too many blocks. What you can do is split the blocks into procedures like for configuring the component properties, and for functions and registering events.

    • Make it understandable for others to understand: Name the functions and components names wisely. Dont make mess, use short explanatory names.

  • Problem starting the service when app closes

    • Some manufacturers try limit the functionality if not has an additional permission(s) like auto-start in especially Redmi phones. This is to prevent apps consuming a lot of battery running in the background. When the phone’s battery optimization is turned on, the system will just not allow the app to start a service.

      This is where ResolveActivity block comes to play. It will automatically check for the conditions that are needed to start the service.

      The block opens the system settings to ask for the permission (ignore battery optimization or auto-start)

      When/to restart(ing) service, the system decides if to really do it…

      If you are using foreground service, then it is just okay to goon without any of the above points needed. :+1:

  • Stopping the service

    • You should use self as component value and exit-foreground for function name to stop the foreground state. Else just use exit function name to close the full service. You can given them a boolean parameter (to remove the notification in close foreground and to restart the service for just close service).

      To close it from outside, use CancelTask function.


Let me know if anything is wrong :+1:

6 Likes

@eagle_vision I just checked the project file which you sent me. There was a small mistake making it not work…

I got it working. It was a problem in the ExtraFunction block. You had put val2.contains("working") instead of val3 :sweat_smile:

11.07.2021_15.23.05_REC

When you get event from web, the counting starts from 0. ExtraFunction had val2 which is responseType in the event value. Thus making extension check response type instead of response content. Everything else is just correct :slight_smile:

Above is the correct block. Just change val2 to val3 and it will be fine :partying_face:

youpiiiiiiiiii you are the best

2 Likes

Good work @Xoma
It’s helped me :heart:

3 Likes

How can I make a donation?
PS: As the extension is open source I suggest you to add the open source tag in it.

2 Likes

I applied this tutorial to (player & Exo) but it didn’t work

Is there anything wrong?

Hi Sara, you have put the function name for “Source” as “Sourse”. The function name is invalid thus extension will ignore the function. Also, you are trying to start the player every 3 seconds…? What is that for?

Edit: Please update the extension to 3.3 (latest release) if your using 3.0.

Thank you very much! You can donate me via Paypal :innocent:

1 Like

Can we create/destroy component in background? to save resources??

Yeah, else just stop the service. Extension will automatically do it for you.

If I need to send notification every morning. How can I stop and restart service?

You can use the latency block (but it will be long).
Then restart the service by functions but you’ll not have a delay.

Will add a periodic block for doing things every interval (recommend day).

1 Like

I decided to use
compare using extra funtion
Interpret code to get current time
then fire every 45s

I should see how that works now

1 Like

Also, beware of background restrictions (especially in high-end Samsung and Redmi devices.)

1 Like

How can we solve that problem? If there was some method to warn users it would be great.

I am not really sure about it.

Samsung has restrictions like if battery saver is enabled it would not work and samsung after android 8+ update also kills the foreground service (have tested it). But its not the same with Redmi.

Redmi/Xiomie devices need auto-start permission just and everything will be fine. Just they dont kill foreground services. But there maybe more restrictions.

You can use the resolve activity block. It will ask for the permission needs to run the app.

2 Likes