我收到的错误是“不幸的是 XXXXXX 已停止”。onContinue 函数中可能有问题。
当进度条完成上传时,我希望他查看下一个布局 MainScreen.class
任何帮助将不胜感激。
这是我的代码:
public class MainActivity extends Activity {
protected static final int TIMER_RUNTIME = 10000; // in ms --> 10s
protected boolean mbActive;
protected ProgressBar mProgressBar;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.apploading);
mProgressBar = (ProgressBar)findViewById(R.id.adprogress_progressBar);
final Thread timerThread = new Thread() {
@Override
public void run() {
mbActive = true;
try {
int waited = 0;
while(mbActive && (waited < TIMER_RUNTIME)) {
sleep(200);
if(mbActive) {
waited += 200;
updateProgress(waited);
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
onContinue();
}
}
};
timerThread.start();
}
@Override
public void onDestroy() {
super.onDestroy();
}
public void updateProgress(final int timePassed) {
if(null != mProgressBar) {
// Ignore rounding error here
final int progress = mProgressBar.getMax() * timePassed / TIMER_RUNTIME;
mProgressBar.setProgress(progress);
}
}
public void onContinue() {
// Moved to the Application to the Main Screen
Intent intent = new Intent(this, MainScreen.class);
startActivity(intent);
}
}