Execute a Dart function in background when the flutter app Autostart's on BOOT_COMPLETED?

bluenile :

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");
}
herbert :

You can use the background_fetch plugin and make sure:

  1. You follow the headless mode documentation
  2. Enable 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 >= 21

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=158163&siteId=1