新线程 handler
class CalculateThread extends Thread {
private Handler handler;
@Override
public void run() {
super.run();
Looper.prepare();
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == 0x1233) {
int upperNum = msg.getData().getInt("UPPER_NUM");
List<Integer> integers = calculateZ(upperNum);
Log.e("ouLog" , integers.toString());
}
}
};
Looper.loop();
}
}
//发送到handler
EditText editText = (EditText)findViewById(R.id.upperNum);
String upperNum = editText.getText().toString();
Message msg = new Message();
msg.what = 0x1233;
Bundle bundle = new Bundle();
bundle.putInt("UPPER_NUM", Integer.parseInt(upperNum));
msg.setData(bundle);
calculateThread.handler.sendMessage(msg);