Reputation: 3
Having trouble to start a new activity after progressbar have loaded. Im getting stucked at progressbar, dont know where I should put the new activity. Any solution to my problem?
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);
}
};
};
}
Upvotes: 0
Views: 4176
Reputation: 777
Please add this to your button click event.
progressDialog = ProgressDialog.show(this, "", "Loading...");
new Thread() {
public void run() {
Intent ddIntent = new Intent(
MainActivity.this, MainWall.class);
startActivity(ddIntent);
progressDialog.dismiss();
}
}.start();
Upvotes: 2
Reputation: 38168
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
Upvotes: 0