How to to run a function in background even after the app is closed?

@bodymindpower has already posted PR link.

Yes, almost. But, as far as I have understood so far, you still need an extension to be able to execute BackgroundTasks. Is that correct?

1 Like

@Shreyash can you please shed some light on these (mysterious) background tasks? :wink:

Since the beginning of AppInventor and its clones, it has been asked, discussed, complained etc. And now it should be possible

2 Likes

Yes, you are right. Extension developers can write services, but not app developers themselves. So you might see purpose-built background task extensions in the future that cater to a few users’ needs. Or perhaps someone could write an extension that takes the name of a procedure and runs it in the background? :thinking:

7 Likes

Definitely true. This is the time to break the barriers. Limitations pause the development.

Services are one of four fundamental app components of Android (other three being Activities, Broadcast Receivers and Content Providers). They can perform long running tasks in background, even after the application is closed, for an indefinite period of time.
Some simple use cases of services:

  • Playing music in background
  • Fetching data from a remote server.
  • Downloading files from the internet.

Like Vishwas mentioned, this implementation of services doesn’t directly let app developers to use services currently. They still need to depend on extension devs to write extensions for their specific use case. For example, there could be an extension for playing music in background or a file downloader extension that works even when the app is closed.

And talking about the extension for running procedures in background, I don’t really think it is a good idea. (I’ve changed my mind! :wink: :face_with_hand_over_mouth:) I’d rather there should be inbuilt blocks that would let users harness all the powers of services. Maybe in near future, this might be possible.

11 Likes

Thanks alot for the detailed information!

However, I am not sure what that means exactly or what could cause problems.

Yes, that would be great.

3 Likes

Thank you Shreyas for your detailed reply.
If this barrier is cut, we can develop even more innovatieve extensions which could help the app developers to stretch their wings broader.

It lets the kiwi fly !

3 Likes

It is still possible,
With this repo by @jarlissonlira2 : GitHub - jarlisson2/appinventor-sources at edi1
I am able to generate my BackgroundTasks extension with service element in it,
Now you would have a question in mind that how can it work without update
It’s because main extension information is stored in 4 Json Files inside extension in which 2 of them contains all the annotation and if you add service there then it will work(As a activity inside the json)(Not in extension)

5 Likes

This should finally solve the problem with the outdated ExoPlayer version:
[ grafik ] → @Mika

See e.g. here:

1 Like

Kodular tried to implement Tasks in the past. But they stopped implementing because of bugs
Why not Kodular try again implementing it?
App Inventor implemented but they shutdown the service
f93acbd7dca6bdec4145ba051068147942b4a0fd
What are Tasks?
You can drag and drop invisible components like clock on tasks screen and you can program them in blocks which works in background

Yes, we already know this:

2 Likes

I still don’t understand how it will work. For the compiler to be able to understand these annotations, some changes are required to be done in the Compiler.java and other files, so that the compiler would be able to process them, and, for this particular case, add the <service> tag in AndroidManifest.xml.

1 Like

If so, then his extension should not work because those changes are missing in App Inventor’s compiler till now.

:confused:
But someone has tested his extension and it worked.
Am I missing something?

1 Like

Okay, so to test this out, I created an app containing a service extension in AI2. It got compiled but crashed when I opened it. The same happened with Kodular Creator.

Perhaps, @Atom_Developer might want to answer this.

2 Likes

Yes background extention is working verry gud atom developer done great job

Yes, confirmed.
More precise: I tested his test APK.

2 Likes

Yes, the APK works, apparently because he decompiled it and manually adjusted the Manifest.

I got this last sentence in a post via PM from @Shreyash:
PS: Anyways, after the nb184 release there won’t be any need to decompile the app and you’ll directly be able to use that extension.

1 Like

And this means I was correct. You cannot add Services to your app using an extension unless the nb184 release is out.

2 Likes

I think we already know the answer now.

2 Likes