This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class T4StationService : Service() { | |
var mLocSer: LocationService? = null | |
var mHandler: MyHandler? = null | |
inner class MyHandler(looper: Looper) : Handler(looper) { | |
override fun handleMessage(msg: Message?) { | |
super.handleMessage(msg) | |
// call some function that needs to be called in UI thread | |
} | |
} | |
override fun onCreate() { | |
super.onCreate() | |
// create handler in the main UI thread | |
mHandler = MyHandler(Looper.getMainLooper()) | |
// start a new thread | |
Thread(MyRunnable()).start() | |
} | |
// inner is required to access outter class method | |
inner class MyRunnable : Runnable { | |
override fun run() { | |
// send message to handle running in UI thread | |
val message = mHandler?.obtainMessage(1) | |
message?.sendToTarget() | |
(0..15).map { | |
println("about to sleep") | |
Thread.sleep(1000) | |
} | |
} | |
} | |
} |