Reputation: 6029
In my Flutter app rather than loading the entire app on the screen, I wish to execute a small Dart function in the background as soon as the app receives the Autostart on BOOT_COMPLETED message.
The app should load normally when the user launches it from the launcher, however when the app receives the Autostart on BOOT_COMPLETED message it should just run a small dart function in the background without the app actually loading on the screen.
So far I have used the code from the following git >> https://github.com/oatpano/flutter_boot_startup
However this code will run the entire app on the screen.
I am not a Android developer, so I'm having issues figuring what is exactly going on in the manifest file.
So in the following example I would like to execute the backgroundfunction() only when the app receives the Autostart on BOOT_COMPLETED message
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
void backgroundfunction(){
print("Hello world");
}
Upvotes: 4
Views: 4646
Reputation: 4883
You can use the background_fetch plugin and make sure:
startOnBoot: true
by during configuration of the service which will either use a BOOT_COMPLETED receiver on Android < 21, or a persisted JobService on Android >= 21Upvotes: 3