Take a look at here
You can use AsyncTask<?,?,?>
to run your embedded server in the background of the UI thread. I assume your embedded server called "HelloServer", here is a example code:
public class ToRunServer extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
HelloServer helloServer = null;
try {
helloServer = new HelloServer();
} catch (IOException e) {
e.printStackTrace();
}
try {
HelloServer.start();
System.out.println("SERVER START TRIED");
return true;
} catch (IOException e) {
e.printStackTrace();
System.out.println("SERVER START FAILED");
return false;
}
}
protected void onPostExecute(Boolean result) {
}
}
Then in your UI class or activity class just add a line into your code:
Boolean isServerRunning = new ToRunServer().execute().get();