以下に示すこのクラスを設定するときのコンテキストの必要性について少し混乱しています。このクラスのインスタンスを作成してアクティビティで使用する場合、コンテキストが必要ですか?
次のように、クラスのコンストラクターを次のように設定できます。
public Server(Context myContext)
または、コンテキストをパラメータとして使用せず、コンテキストを使用しない場合:
public Server()
サーバークラスのコードの詳細については、次を参照してください。
public class Server {
private TextView serverStatus;
public TextView receivedCommand;
public String line = null;
// default ip
// public static String SERVERIP = "192.168.1.001";
public static String SERVERIP = "localhost";
// designate a port
public static final int SERVERPORT = 8080;
private Handler handler = new Handler();
private ServerSocket serverSocket;
public Server(){
SERVERIP = getLocalIpAddress();
Thread fst = new Thread(new ServerThread());
fst.start();
}
public class ServerThread implements Runnable {
// ... the rest of the code