Android handler question
I created a separate thread file
Refer to the thread in another activity.
There is a problem when trying to change UI with handler.
This part is nullpoint.
Message hdmsg= handler.obtainMessage();
I do not know which part is the problem.
ClientThread.java
public class ClientThread extends Thread{
public ClientThread() {
}
public void run(){
try{
Thread currThread = Thread.currentThread();
while (currThread == thisThread) {
String recvData = ct_in.readUTF();
StringTokenizer st = new StringTokenizer(recvData, SEPARATOR);
int command = Integer.parseInt(st.nextToken());
switch (command) {
case MDY_WAITINFO: {
StringTokenizer st1 = new StringTokenizer(st.nextToken(), DELIMETER);
StringTokenizer st2 = new StringTokenizer(st.nextToken(), DELIMETER);
/*
code~
*/
Message hdmsg= handler.obtainMessage();
hdmsg.obj=st;
handler.sendMessage(hdmsg);
break;
}
}
}
} catch (IOException e) {
System.out.println(e);
release();
}
}
}
RoomList.java
public class HostRoomListActivity extends AppCompatActivity {
public static Handler handler;
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SocketHostRoom client = new SocketHostRoom();
client.start();
handler = new Handler(){
public void handleMessage(Message msg){
String txtmsg = msg.obj.toString();
}
};
}
class SocketHostRoom extends Thread{
public void run(){
ClientThread thread = new ClientThread();
thread.start();
thread.requestHostRoomList();
}
}
}
}