How to run service not on main thread?
问题 I'm trying to launch service and then open socket to have connection with server. On button click I create new Thread and then start service. Thread t = new Thread(){ public void run(){ mIntent= new Intent(MainActivity.this, ConnectonService.class); mIntent.putExtra("KEY1", "Value used by the service"); context.startService(mIntent); } }; t.start(); Then on service , I try to open socket and have connection with server @Override public int onStartCommand(Intent intent, int flags, int startId)