public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HttpHandelar httpHandelar = new HttpHandelar();
HttpThread h = new HttpThread(httpHandelar);
h.start();
}
class HttpThread extends Thread {
public Handler handler;
public HttpThread(Handler handler) {
this.handler = handler;
}
@Override
public void run() {
super.run();
Message m = handler.obtainMessage();
HashMap<String, String> h = new HashMap<String, String>();
h.put("a", "aa");
h.put("b", "bb");
h.put("c", "cc");
h.put("d", "dd");
m.obj = h;
handler.sendMessage(m);
}
}
class HttpHandelar extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
HashMap<String, String> mh = (HashMap) msg.obj;
Set<String> key = mh.keySet();
for (String gk : key) {
System.out.println(mh.get(gk));
}
}
}
}
0 件のコメント:
コメントを投稿