我遇到问题我在进度条达到100%后无法启动新活动。这是我的代码我在startActivity遇到错误。 Main.java package com.example.hprogressbarexmaple;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ProgressBar;
public class HProgressBarExmaple extends Activity {
protected static final int MAX_PROGRESS = 100;
protected static final long SLEEP_TIME = 200;
/** Called when the activity is first created. */
ProgressBar myProgressBar;
int myProgress = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myProgressBar = (ProgressBar) findViewById(R.id.myProgress);
new Thread(myThread).start();
}
private Runnable myThread = new Runnable() {
@Override
public void run() {
// don't hard code things, use a constant for max progress value
while (myProgress < MAX_PROGRESS) {
try {
myHandle.sendMessage(myHandle.obtainMessage());
// same
Thread.sleep(SLEEP_TIME);
} catch (Exception ex) {
// never live an empty catch statement, you are missing
// exceptions and
// can't correct them
Log.e("MyCurrentClass",
"Error during async data processing", ex);
}// catch
}// while
// start new activity here
startActivity(HProgressBarExmaple.this, List.class);
}// met
Handler myHandle = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
myProgress++;
myProgressBar.setProgress(myProgress);
}
};
};
}
我搜索了很多,但我无法得到解决方案。如果我出错了,请帮助我并纠正我。
答案 0 :(得分:1)
尝试这种方式:
Intent intent = new Intent(HProgressBarExmaple.this,List.class);
HProgressBarExmaple.this.startActivity(intent);
不要忘记在List Activity
manifest.xml