First declare a global handler,
Handler handler=null;
Then create a handler in your onCreate () like this,
Handler handler=new Handler() { public void handleMessage(Message msg) { if(msg.what==0) { Toast.makeText(ClientActivity.this,"Your Toast Mesage Goes here",Toast.LENGTH_LONG).show(); } } };
And now in your Runnable class add this line after "Log.d("ClientActivity", "C: Sent.");"
handler.sendEmptyMessage(0);
The problem you are facing is that you cannot update the user interface from runnable. Handlers connect you to the main user interface. Therefore, you need to pass the message to your handler from your Runnable.
source share