1

我想制作包含倒计时的程序。即使应用程序关闭,我也希望倒计时继续运行。我知道我应该使用 getter 和 setter。

编辑:每次按下按钮时,都会出现错误。有谁知道我该如何解决这个问题?

启动服务:

        public void onClick(View arg0) {                            //countdown starts by preesing a button
            // TODO Auto-generated method stub
            ssf = Integer.parseInt(essf.getText().toString());
            Intent openCountDownService = new Intent("julian.mangelberger.ultravioletobservation.COUNTDOWNSERVICE");
            startService(openCountDownService);
        }

服务:

import julian.mangelberger.ultravioletobservation.TabMainActivity;
import android.app.IntentService;
import android.content.Intent;

public class CountDownService extends IntentService {

public CountDownService(String name) {
    super(name);
    // TODO Auto-generated constructor stub
}

@Override
protected void onHandleIntent(Intent intent) {
    while (TabMainActivity.progressBarStatus <= 100) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        TabMainActivity.progressBarStatus++;
        TabMainActivity.progressbar1.setProgress(TabMainActivity.progressBarStatus);

    }
}


}
4

0 回答 0