- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
应用简介:
执行步骤为:
问题:
Rarely and randomly UI stops reacting on user and runnables not executed on UI thread. At the same time background threads continue working as normal: camera output is visible on TextureView and ImageAnaliser continue receive images from Camera.
有没有人对如何查找/调试此类行为的原因有任何建议?或者有什么想法会导致这种情况?
我已经尝试过:
这里是AnaliseFragment的简化代码:
public class AnaliseFragment extends Fragment {
private HandlerThread mBackgroundThread;
private Handler mBackgroundHandler;
private ImageAnalyser mImageAnalyser;
// listener is attached to camera capture session and receives every frame
private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
= new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image nextImage = reader.acquireLatestImage();
mBackgroundHandler.post(() ->
try {
mImageAnalyser.AnalizeNextImage(mImage);
}
finally {
mImage.close();
}
);
}
};
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
mImageAnalyser = new ImageAnalyser();
mImageAnalyser.onResultAvailable(boolResult -> {
// Runnable posted, but never executed
new Handler(Looper.getMainLooper()).post(() -> reportToActivityAndUpdateUI(boolResult));
});
}
@Override
public void onResume() {
super.onResume();
startBackgroundThread();
}
@Override
public void onPause() {
stopBackgroundThread();
super.onPause();
}
private void startBackgroundThread() {
if (mBackgroundThread == null) {
mBackgroundThread = new HandlerThread("MyBackground");
mBackgroundThread.start();
mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
}
}
private void stopBackgroundThread() {
mBackgroundThread.quitSafely();
try {
mBackgroundThread.join();
mBackgroundThread = null;
mBackgroundHandler = null;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
ImageAnalyser 的简化代码:
public class ImageAnalyser {
public interface ResultAvailableListener {
void onResult(bool boolResult);
}
private ResultAvailableListener mResultAvailableListener;
public void onResultAvailable(ResultAvailableListener listener) { mResultAvailableListener = listener; }
public void AnalizeNextImage(Image image) {
// Do heavy analysis and put result into theResult
mResultAvailableListener.onResult(theResult);
}
}
最佳答案
UI 线程中有一些长时间运行的操作。尝试 profile您的应用程序找出是什么阻塞了您的主线程。
关于MainLooper 未执行 Android Runnable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55647206/
我试图找到一些关于 tk.mainloop() 与 root.mainloop() 的使用的问答或文章,但没有成功。 我的问题是:这两种用途之间有什么区别吗?对我来说,正确的方法是使用 tk_inst
我是 Stack Overflow 的新成员。我找到了这个线程,但不允许对其发表评论或提问,所以我想我只能在这里引用它:How can I make a in interactive list in
我是 python 的新手,正在尝试设置功能测试环境。测试环境应通过 DBus 接收信号并对其进行评估。 DBus 信号使用 GLib MainLoop。我有以下封装循环的类: class Signa
我有一个 Python 脚本,可以根据 D-Bus 事件执行操作,这是其简化版本: import dbus from dbus.mainloop.glib import DBusGMainLoop i
有没有办法让我在后台运行 mainloop()?我不想增加线程的复杂性。提前致谢。 最佳答案 没有。 GUI 框架的主循环必须始终在前台运行。 关于Python:有没有办法让我在后台运行 mainlo
这不是 Python tkinter mainloop not quitting on closing the window 的副本 我有一个基于 tkinter 构建的应用程序。我观察到有时在我使用
我正在尝试创建一个使用 tkinter 显示图像的程序。到目前为止,我编写的代码完美地显示了图像,但是程序在 tkinter 窗口关闭之前不会继续。我想知道是否有任何函数代替 .mainloop()
我正在使用 wxWdigets(确切地说是 wxPython)来显示一些模式对话框。 本页https://wxpython.org/Phoenix/docs/html/wx.EventLoopBase
应用简介: 我有 Cordova/Ionic 应用程序和自定义 Cordova 插件以执行 native 代码。 插件包含单独的 CameraActivity(扩展 FragmentActivity)
在主程序主循环中,我正在通过调用 tibemsMsgConsumer_Receive 来收听 EMS 主题。同时,我想在特定时间退出程序,比如下午 5 点。我该如何实现? 我尝试使用以下代码,但在没有
我有来自 online tutorial 的以下代码通过制作一个在单击鼠标时改变状态的 parking 灯来学习基于事件的编程。这是我的全部代码: import turtle turtle.setup
我们在项目中使用Python2.3和wxPython V2.4.2.4。而且运行良好。现在我们将其升级到Python2.7和wxPython2.8.12.1。我们的项目在新版本中编译得很好。但在我们的
我正在尝试创建一个基本的 Tkinter 窗口。 根据在线教程,要创建一个窗口,必须使用以下命令: import Tkinter window=Tkinter.Tk() window.mainloop
我有一个模块使用 python“threading”实现并发,使用“signal”实现关闭 Hook : signal.signal(signal.SIGINT, self.shutdownhook)
我是 Android 世界的新手。跟随和我应该使用哪个在主线程上运行方法之间到底有什么区别? 1) Handler mainHandler = new Handler(getApplicationCo
到现在为止,我曾经用 tk.mainloop() 结束我的 Tkinter 程序,否则什么都不会出现!见例子: from Tkinter import * import random import t
我在我的 Python 应用程序中使用 PyGObject 的 GLib.MainLoop() 并有一个问题。 是否可以处理 loop.run() 中引发的 Python 异常? 例如,我正在使用 G
好吧,我正在编写一个程序,以对应该在循环中显示字母的文本进行动画处理: Th 不过 汤姆 托马 托马斯 托马斯 托马斯苏 托马斯成功... 依此类推,直到重置,然后再次循环。问题是, tkinter
我不熟悉 python,特别是 GUI 问题。我正在尝试添加其他类的图像,我找到了一种添加其他对象但不添加图像的方法。此代码工作正常: from Tkinter import * from PIL i
我正在使用 Python 进行编程,但有几个问题无法在任何地方找到答案(请阅读所有问题,因为它们构成了我的最后一个问题): 1..mainloop() 的作用是什么?我阅读了 Stack Overfl
我是一名优秀的程序员,十分优秀!