0

所以,是的,我的线程没有执行,也没有在其中执行代码。我只是想从我的 sdcard 运行一个 shell 脚本,并显示一个“加载”圆圈或“进度”圆圈或任何你想要调用它的东西。当我单击按钮运行线程时,我得到进度/加载栏/圆圈,但它只是坐在那里,什么也不做。我看过一些例子,但仍然无法弄清楚我做错了什么。这是我的代码:

package com.cydeon.plasmamodz;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeoutException;

import com.stericson.RootTools.*;
import com.stericson.RootTools.exceptions.RootDeniedException;
import com.stericson.RootTools.execution.CommandCapture;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Install extends Activity{

private static ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.install);
    Button bInstall = (Button) findViewById(R.id.bInstallTheme);
    bInstall.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            showDialog();
        }
    });
}


public void showDialog(){
    progressDialog = ProgressDialog.show(Install.this, "", "Installing Theme", true);
    Thread thread = new Thread();
    thread.start();
}

public void run(){
    try{
        Thread.sleep(1000);
        CommandCapture command = new CommandCapture(0, "su", "sh /sdcard/plasma/scripts/install.sh");
        try {
            RootTools.getShell(true).add(command).waitForFinish();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        } catch (RootDeniedException e) {
            e.printStackTrace();
        }
    }catch (InterruptedException e){
        e.printStackTrace();
    }
    handler.sendEmptyMessage(0);
}

private static Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        progressDialog.dismiss();
    }
};

}

那么,我做错了吗?为什么它不能运行我的代码?谢谢!

4

1 回答 1

1

线程不知道要运行什么。改变

public class Install extends Activity{

public class Install extends Activity implements Runnable {

和改变

Thread thread = new Thread();

Thread thread = new Thread(this);
于 2013-03-20T23:27:59.923 回答