Advertisement
ZelimkhanMezhidov

Untitled

Mar 25th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.29 KB | None | 0 0
  1. class MyAppService: Service() {
  2.  
  3.     private var serviceLooper: Looper? = null
  4.     private var serviceHandler: ServiceHandler? = null
  5.  
  6.     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
  7.  
  8.         HandlerThread("ServiceStartArguments", Process.THREAD_PRIORITY_BACKGROUND).apply {
  9.             start()
  10.             // Get the HandlerThread's Looper and use it for our Handler
  11.             serviceLooper = looper
  12.             serviceHandler = ServiceHandler(looper)
  13.  
  14.             Thread() {
  15.                 runBlocking { // this: CoroutineScope
  16.                     launch {
  17.                         globalEventIncomePush.collect { model ->
  18.                             createNotificationChannel(model.channelId,model.channelId, this@MyAppService)
  19.                             simpleNotification(this@MyAppService, model.channelId, model.notificationId, model.textTitle, model.textContext)
  20.                         }
  21.                     }
  22.                 }
  23.             }.start()
  24.         }
  25.  
  26.         return super.onStartCommand(intent, flags, startId)
  27.     }
  28.  
  29.     override fun onBind(p0: Intent?): IBinder? {
  30.         return null
  31.     }
  32.  
  33.     private inner class ServiceHandler(looper: Looper) : Handler(looper) {
  34.         override fun handleMessage(msg: Message) {}
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement