68.7 Sending a Message to the Remote Service
All that remains before testing the application is to implement the sendMessage() method in the MainActivity class which is configured to be called when the button in the user interface is touched by the user. This method needs to check that the service is connected, create a bundle object containing the string to be displayed by the server, add it to a Message object and send it to the server:
fun sendMessage(view: View) {
if (!isBound) return
val msg = Message.obtain()
val bundle = Bundle()
bundle.putString("MyString", "Message Received")
msg.data = bundle
try {
myService?.send(msg)
} catch (e: RemoteException) {
...