2013-03-20 72 views
0

所以是的,我的線程沒有執行,或者執行其中的代碼。我只是想從我的SD卡上運行一個shell腳本,並顯示一個「加載」圈子或「進度」圈子或任何你想調用它。當我點擊按鈕來運行線程時,我得到進度/加載欄/圓圈,但它只是坐在那裏,什麼都不做。我已經看過一些例子,但仍然無法弄清楚我做錯了什麼。這是我的代碼:Android - 線程沒有執行

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(); 
    } 
}; 

} 

所以,我做錯了什麼?爲什麼它不運行我的代碼?謝謝!

回答

1

線程不知道要運行什麼。更改

public class Install extends Activity{ 

public class Install extends Activity implements Runnable { 

,改變

Thread thread = new Thread(); 

Thread thread = new Thread(this);