在设置如下所示的此类时,对上下文的需求有点困惑。在创建此类的实例以在我的活动中使用它时,我是否需要上下文?
我可以像这样为类设置构造函数:
public Server(Context myContext)
或没有上下文作为参数,不使用上下文:
public Server()
现在获取更多来自 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