1

I am working in flutter background fetch but it is giving me some error in headless task.

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Application android.app.Activity.getApplication()' on a null object reference

Application.java package com.xxxx.xxxxapp;

import com.transistorsoft.flutter.backgroundfetch.BackgroundFetchPlugin;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
  @Override
  public void onCreate() {
    super.onCreate();
    BackgroundFetchPlugin.setPluginRegistrant(this);
  }

  @Override
  public void registerWith(PluginRegistry registry) {
    GeneratedPluginRegistrant.registerWith(registry);
  }
}
Sudhansu Joshi
  • 235
  • 7
  • 20
  • I have the same issue. I've found the following thread https://github.com/transistorsoft/flutter_background_fetch/issues/35 It says some of the plugins have to use registrar.activity() != null for headless to work properly. – Mangirdas Skripka Jan 27 '20 at 06:50

1 Answers1

0

Headless events on Android and iOS is yet to be supported in Flutter due to OS level limitations. Here's the open ticket for this feature request. A workaround would be to wake the app using WorkManager and execute the background task.

Omatt
  • 8,564
  • 2
  • 42
  • 144