fix thread blocking,add android service Looper,Handler

This commit is contained in:
csf 2022-04-17 23:29:27 +08:00
parent 51ad81e48f
commit a348ba3d7e
2 changed files with 10 additions and 1 deletions

View File

@ -124,6 +124,9 @@ class MainService : Service() {
}
}
private var serviceLooper: Looper? = null
private var serviceHandler: Handler? = null
// jvm call rust
private external fun init(ctx: Context)
private external fun startServer()
@ -174,6 +177,11 @@ class MainService : Service() {
override fun onCreate() {
super.onCreate()
HandlerThread("Service", Process.THREAD_PRIORITY_BACKGROUND).apply {
start()
serviceLooper = looper
serviceHandler = Handler(looper)
}
updateScreenInfo()
initNotification()
startServer()
@ -287,7 +295,7 @@ class MainService : Service() {
}
} catch (ignored: java.lang.Exception) {
}
}, null)
}, serviceHandler)
}
Log.d(logTag, "ImageReader.setOnImageAvailableListener done")
imageReader?.surface

View File

@ -346,6 +346,7 @@ class ConnectionManager extends StatelessWidget {
icon: Icon(Icons.close),
onPressed: () {
FFI.setByName("close_conn", entry.key.toString());
FFI.invokeMethod("cancel_notification", entry.key);
},
label: Text(translate("Close")))
],