在我的服务中,值每隔1秒更新一次。在活动中使用运行服务结果
Timer timer = new Timer();
timer.scheduleAtFixedRate(
new java.util.TimerTask() {
@Override
public void run() {
if(Serve.Connecting){
tv = (TextView)findViewById(R.id.textView1);
tv.setText("Connecting");
ProgressBar PB = (ProgressBar) findViewById(R.id.progressBar1);
PB.setProgress(25);
}
if(Serve.Connected){
tv = (TextView)findViewById(R.id.textView1);
tv.setText("Connected");
ProgressBar PB = (ProgressBar) findViewById(R.id.progressBar1);
PB.setProgress(50);
}
if(Serve.Connected && Serve.loading.FALSE){
tv = (TextView)findViewById(R.id.textView1);
tv.setText("Loading");
ProgressBar PB = (ProgressBar) findViewById(R.id.progressBar1);
PB.setProgress(75);
}
if(Serve.Connected && Serve.loading){
tv = (TextView)findViewById(R.id.textView1);
tv.setText("Done");
ProgressBar PB = (ProgressBar) findViewById(R.id.progressBar1);
PB.setProgress(100);
Intent intent = new Intent(Loadingpage.this, Setup.class);
startActivity(intent);
finish();
frstscr=false;
}
}},
200, 500
);
,但它没有工作,所以我使用该处理器的示例尝试:正在运行的活动,所以我不能更新.tried在活动使用的定时器的新成果和更新textviews或功能运行一次
private Handler handler = new Handler();
runnable.run();
private Runnable runnable = new Runnable()
{
public void run()
{
//
// Do the stuff
//
handler.postDelayed(this, 1000);
}};
但没有工作,任何想法? 我甚至使用while(frstscrn){fun}其中frstscrn是布尔值,标识该活动正在运行
您是否调用handler.post(runnable)? – pskink 2013-05-12 11:39:40
是不是通过调用该行runnable.run(); ?? – 2013-05-12 11:41:57