我一直在寻找这个,但没有找到任何包或在Flutter中安排后台任务的方法.就像在Android中一样WorkManager,AlarmManager.
我知道我可以使用这些类来访问这些类MethodChannel,但我想要一些适用于iOS和Android的东西.
(非常令人失望的是,移动框架无法安排后台任务).
我有一个在线播放音频的音乐应用程序。唯一的问题是每次我退出应用程序时它都会被杀死,这对用户不利。即使在退出后,他们也需要它在后台继续运行。我怎样才能做到这一点?
我正在 Flutter 应用程序中开发本机 Android 小部件。其中有刷新按钮,点击后我必须在 Flutter 代码中调用一个方法。我正在使用 Flutter Method Channel 进行通信,并且当应用程序处于前台时它工作正常。但是当应用程序最小化或关闭时它不起作用。我收到错误PlatformException(NO_ACTIVITY, null, null)。下面是我的代码。
安卓(AppWidgetProvider)
if (methodChannel == null && context != null) {
FlutterMain.startInitialization(context)
FlutterMain.ensureInitializationComplete(context, arrayOf())
// Instantiate a FlutterEngine.
val engine = FlutterEngine(context.applicationContext)
// Define a DartEntrypoint
val entrypoint: DartEntrypoint = DartEntrypoint.createDefault()
// Execute the DartEntrypoint within the FlutterEngine.
engine.dartExecutor.executeDartEntrypoint(entrypoint)
// Register Plugins when in background. When there
// is already an engine running, this will be ignored (although there will be some
// warnings in the …Run Code Online (Sandbox Code Playgroud)