fix thread blocking,add android service Looper,Handler
This commit is contained in:
		
							parent
							
								
									51ad81e48f
								
							
						
					
					
						commit
						a348ba3d7e
					
				| @ -124,6 +124,9 @@ class MainService : Service() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private var serviceLooper: Looper? = null | ||||||
|  |     private var serviceHandler: Handler? = null | ||||||
|  | 
 | ||||||
|     // jvm call rust |     // jvm call rust | ||||||
|     private external fun init(ctx: Context) |     private external fun init(ctx: Context) | ||||||
|     private external fun startServer() |     private external fun startServer() | ||||||
| @ -174,6 +177,11 @@ class MainService : Service() { | |||||||
| 
 | 
 | ||||||
|     override fun onCreate() { |     override fun onCreate() { | ||||||
|         super.onCreate() |         super.onCreate() | ||||||
|  |         HandlerThread("Service", Process.THREAD_PRIORITY_BACKGROUND).apply { | ||||||
|  |             start() | ||||||
|  |             serviceLooper = looper | ||||||
|  |             serviceHandler = Handler(looper) | ||||||
|  |         } | ||||||
|         updateScreenInfo() |         updateScreenInfo() | ||||||
|         initNotification() |         initNotification() | ||||||
|         startServer() |         startServer() | ||||||
| @ -287,7 +295,7 @@ class MainService : Service() { | |||||||
|                             } |                             } | ||||||
|                         } catch (ignored: java.lang.Exception) { |                         } catch (ignored: java.lang.Exception) { | ||||||
|                         } |                         } | ||||||
|                     }, null) |                     }, serviceHandler) | ||||||
|                 } |                 } | ||||||
|             Log.d(logTag, "ImageReader.setOnImageAvailableListener done") |             Log.d(logTag, "ImageReader.setOnImageAvailableListener done") | ||||||
|             imageReader?.surface |             imageReader?.surface | ||||||
|  | |||||||
| @ -346,6 +346,7 @@ class ConnectionManager extends StatelessWidget { | |||||||
|                         icon: Icon(Icons.close), |                         icon: Icon(Icons.close), | ||||||
|                         onPressed: () { |                         onPressed: () { | ||||||
|                           FFI.setByName("close_conn", entry.key.toString()); |                           FFI.setByName("close_conn", entry.key.toString()); | ||||||
|  |                           FFI.invokeMethod("cancel_notification", entry.key); | ||||||
|                         }, |                         }, | ||||||
|                         label: Text(translate("Close"))) |                         label: Text(translate("Close"))) | ||||||
|                   ], |                   ], | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user