我在我的小游戏中实现了进度条,如下所示
gameProgressBar =(ProgressBar)findViewById(R.id.GameProcess);
thrd = new Thread(progressBarThread);
thrd.start();
}
//Progress bar function
private Runnable progressBarThread = new Runnable(){
public void run() {
// TODO Auto-generated method stub
while (GameProgressCount<60){ //60 = 1 minute
try{
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(1000);
}
catch(Throwable t){
}
}
thrd.stop();
}
Handler myHandle = new Handler(){
@Override
public void handleMessage(Message msg) {
GameProgressCount++;
gameProgressBar.setProgress(GameProgressCount);
}
};
我的问题是,当我单击设备的返回/主页按钮时,应用程序正在最小化(或转到上一个屏幕),但进度条线程将在后台运行。当我最小化/打开应用程序屏幕时,是否可以暂停线程并恢复。
谢谢