Guest User

Untitled

a guest
Oct 20th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.84 KB | None | 0 0
  1. class LocalService : Service() {
  2.     // Binder given to clients
  3.     private val mBinder: IBinder = LocalBinder()
  4.  
  5.     // Random number generator
  6.     private val mGenerator: Random = Random()
  7.  
  8.     /**
  9.      * Class used for the client Binder.  Because we know this service always
  10.      * runs in the same process as its clients, we don't need to deal with IPC.
  11.      */
  12.     inner class LocalBinder : Binder() {
  13.         // Return this instance of LocalService so clients can call public methods
  14.         val service: LocalService
  15.             get() =// Return this instance of LocalService so clients can call public methods
  16.                 this@LocalService
  17.     }
  18.  
  19.     override fun onBind(intent: Intent?): IBinder {
  20.         return mBinder
  21.     }
  22.  
  23.     /** method for clients  */
  24.     val randomNumber: Int
  25.         get() = mGenerator.nextInt(100)
  26. }
Advertisement
Add Comment
Please, Sign In to add comment