加载进度条后无法启动新活动。我被困在进度条,不知道我应该把新活动放在哪里。我问题的任何解决方案?
ProgressBar myProgressBar;
int myProgress = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
myProgressBar=(ProgressBar)findViewById(R.id.progressbar_Horizontal);
new Thread(myThread).start();
}
private Runnable myThread = new Runnable(){
public void run() {
// TODO Auto-generated method stub
while (myProgress<100){
try{
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(50);
}
catch(Throwable t){
}
}
}
Handler myHandle = new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
myProgress++;
myProgressBar.setProgress(myProgress);
}
};
};
}
答案 0 :(得分:2)
请将此添加到您的按钮点击事件中。
progressDialog = ProgressDialog.show(this, "", "Loading...");
new Thread() {
public void run() {
Intent ddIntent = new Intent(
MainActivity.this, MainWall.class);
startActivity(ddIntent);
progressDialog.dismiss();
}
}.start();
答案 1 :(得分:0)
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",e );
}//catch
}//while
//start new activity here
startActivity( MyClass.this, NewActivity.class );
}//met