安卓如何重复调用同一个线程里的run方法?

比如在一个页面里两个按钮,点第一个,成功执行run方法里的语句,然后点第二个就没反应,要么就闪退

闪退报什么错,你将代码贴出来

public class Test2Activity extends Activity implements OnClickListener {
private TextView start_text;
private EditText team_Name, music_Name;
private String get_method;
private boolean thIsStart = false;

Thread th;

@SuppressLint("HandlerLeak")
private Handler handler = new Handler() {

    @Override
    public void handleMessage(Message msg) {
        // TODO Auto-generated method stub
        super.handleMessage(msg);
        Log.i("handler", "into handle");
        String result = msg.obj.toString();
        Log.i("mytag", "成功:" + result);
        // 将WebService返回的结果显示在TextView中
        start_text.setText("结果:" + result);
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test2);
    start_text = (TextView) findViewById(R.id.start_text);
    team_Name = (EditText) findViewById(R.id.teamName);
    music_Name = (EditText) findViewById(R.id.musicName);

    findViewById(R.id.start_btn).setOnClickListener(this);
    findViewById(R.id.pause_btn).setOnClickListener(this);
    findViewById(R.id.continue_btn).setOnClickListener(this);

    th = new Thread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub

            try {
                Message msg = new Message();
                FoundWebServices fws = new FoundWebServices();
                msg.obj = fws.getRemoteInfo(team_Name.getText().toString(),
                        music_Name.getText().toString(), get_method);
                handler.sendMessage(msg);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Log.d("mytag", e.toString());
            } finally {
            }
        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.test2, menu);
    return true;
}

@Override
public void onClick(View v) {

    switch (v.getId()) {
    case R.id.start_btn:
        get_method = "getSynTime";
        break;
    case R.id.pause_btn:
        get_method = "pauseMusic";
        break;
    case R.id.continue_btn:
        get_method = "continueMusic";
        break;
    }
    if (thIsStart == false) {
        thIsStart = true;
        th.start();
    } else {
        th.run();
    }

}

}


然后run()里面调用getRemoteInfo()方法取得web services里的方法返回值

public String getRemoteInfo(String teamName, String musicName, String methodName)
throws Exception {
String WSDL_URI = "http://10.2.5.231:8080/DanceMusicWebServices/MusicSynPort?wsdl";// wsdl的uri
String namespace = "http://services.dustray.cn/";// namespace
//methodName = "getSynTime";// 要调用的方法名称

    SoapObject request = new SoapObject(namespace, methodName);
    // 设置需调用WebService接口需要传入的两个参数mobileCode、userId
    request.addProperty("arg0", teamName);
    request.addProperty("arg1", musicName);
    // 创建SoapSerializationEnvelope 对象,同时指定soap版本号(之前在wsdl中看到的)
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapSerializationEnvelope.VER10);
    envelope.bodyOut = request;// 由于是发送请求,所以是设置bodyOut
    envelope.dotNet = false;// 是否是.net开发的webservice
    HttpTransportSE httpTransportSE = new HttpTransportSE(WSDL_URI);
    httpTransportSE.call(namespace + methodName, envelope);// 调用
    // 获取返回的数据
    SoapObject object = (SoapObject) envelope.bodyIn;
    // 获取返回的结果
    try {
        result = object.getProperty(0).toString();

    } catch (Exception e) {
        result = "失败";

    }

    return result;

}

我建议你应该将Thread封装成一个方法,你点击按钮不同的发送消息,在主线程中里分别处理

把错误信息log发出来