Skip to content

Instantly share code, notes, and snippets.

@matthewrkula
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewrkula/97f295dfa721b85e6626 to your computer and use it in GitHub Desktop.
Save matthewrkula/97f295dfa721b85e6626 to your computer and use it in GitHub Desktop.
try {
final Socket socket = serverSocket.accept();
final boolean[] accept = { false };
new Handler(Looper.getMainLooper()).post(() -> {
new AlertDialog.Builder(lobbyActivity)
.setTitle("Incoming Request")
.setMessage("Incoming Game Request")
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
accept[0] = true;
try {
socket.getOutputStream().write( 1);
} catch (IOException e) {
e.printStackTrace();
}
new Handler(Looper.getMainLooper()).post(() -> {
Log.d("GAME", "Starting game from connection.");
AndroidLauncher.network = new NetworkHandler(socket);
Intent intent = new Intent(lobbyActivity, AndroidLauncher.class);
lobbyActivity.startActivity(intent);
});
})
.setNegativeButton(android.R.string.no, (dialog, which) -> {
accept[0] = false;
try {
socket.getOutputStream().write(0);
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
});
} catch (IOException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment