在我的服务中,值每 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
);
但它没有用,所以我尝试使用该处理程序示例:
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 是布尔值,用于标识活动正在运行