- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序将文件发送到 ftp 服务器。我通过MethodChannel在android上用java发送文件。
这些部分可以在单线程中完成所有工作。但我想发送带有 AsyncTask (java) 和背景的文件。
此外,我需要使用 MethodChannel 将文件上传结果的结果发送到 Flutter。
我怎样才能做到这一点?
我试图在 AsyncTask 的 doInBackground 上使用 MethodChannel.Result 但它给了我这个错误:
Caused by: java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #2
最佳答案
所以为了解决'@UiThread必须在主线程上执行'的错误。
我用过这个
runOnUiThread(new Runnable() {
@Override
public void run() {
//call the methodChannel.invokeMethod here to avoid @UiThread exception
}
});
class NativeBackground {
final methodChannel = MethodChannel('your.apps.channel/background');
static NativeBackground _instance;
factory NativeBackground() => _instance ? ? = NativeBackground._();
NativeBackground._() {
handlePlatformChannelMethods();
}
Future <void> handlePlatformChannelMethods() async {
methodChannel.setMethodCallHandler((methodCall) {
print('NativeChanell background...');
print(methodCall.method + '(' + methodCall.arguments + ')');
});
}
}
关于flutter - MethodChannel 的后台监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61406833/
有没有办法在不需要时处理 MethodChannel/EventChannel ?我问是因为我想为对象创建多个方法/事件 channel 。 例子: class Call { ... fields
我的应用程序将文件发送到 ftp 服务器。我通过MethodChannel在android上用java发送文件。 这些部分可以在单线程中完成所有工作。但我想发送带有 AsyncTask (java)
所以我在大约 4 个月前写了一个 Flutter 应用程序。现在我想做一个小改动,但我不能再编译应用程序了,因为 GeneratedPluginRegistrant.registerWith(this
Flutter docs 中的示例将他们正在使用的 MethodChannel(与 native 主机通信)直接在使用它的 Widget 中声明为 static const。为了将其中一些分离,我正在
我正在尝试使用一些 native 代码为 Flutter 创建一个 Facebook 身份验证插件。我已经让代码在一个完全 native 的测试项目上工作,但无法让它在 android 插件项目中工作
在Flutter中,平台 channel 分为三种,想了解一下它们的区别。 最佳答案 这些 channel 用于在原生代码(项目内的插件或原生代码)和 Flutter 框架之间进行通信。 方法 cha
得到这个奇怪的错误。似乎 MethodChannel 正在转换为 int 而不是 bool? 06-07 00:16:26.589 3678 4993 E flutter : [ERROR:top
我在应用程序关闭时尝试打开 android Activity 时失败。在下面的代码中看到,当我收到来自 firebase 的数据通知时,当应用程序在后台时,我应该使用 MethodChannel 打开
我正在编写一个原生插件,在某些情况下,它必须调用应用程序的 Flutter 部分中的函数,该插件是用 Dart 编写的。它是如何实现的,解释如下: https://flutter.io/platfor
我有一个 flutter 项目(插件),它也使用一些 native java 代码。为了在 dart 和 java 之间进行通信,我使用了 MethodChannel.invokeMethod。这在
我正在编写一个原生插件,在某些情况下,它必须调用应用程序的 Flutter 部分中的函数,用 Dart 编写。它是如何实现的,在这里解释: https://flutter.io/platform-ch
我正在尝试这里的示例 https://flutter.dev/docs/development/platform-integration/platform-channels#step-1-create
我有一个 Flutter 项目,试图在 Flutter 和 iOS Native 之间建立双向通信。到目前为止,它从 Flutter 到 iOS 都运行良好,但反之则无声。当我从 iOS 调用该方法时
好吧,我正在尝试使用 PlatformChannels 从 flutter 导入 Java 代码,我在 Ubuntu 上并且收到该错误,也许这是一个 Java 错误,请创建我的项目 flutter c
在开始我的问题之前,我想指出这个问题并不相似。 Difference between writing platform specific code vs dart:ffi code .在这里,发问者问
我是一名优秀的程序员,十分优秀!