Reputation: 1065
After clicking a button it calls a function show from which a dialog box appears. I want the dialog box to remain for about 4 second, get dismissed and anothet activity to get opened. With the code that I have written it waits for 4 seconds, shows the dialog box and immediately goes on to the next activity.
public void show()
{ final Dialog dialog = new Dialog(invoice.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.popup);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = Math.round((width * 10) / 15);
lp.height = Math.round(height / 3);
dialog.getWindow().setAttributes(lp);
Intent intent = new Intent(invoice.this, First_grid.class);
intent.putExtra("yo", 0);
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= 16) {
//The code below is for the cool transition effect that happens once the player clicks the play button..!
Bundle translateBundle = ActivityOptions.makeCustomAnimation(invoice.this,
R.anim.activity_slide_up, R.anim.activity_slide_out_upwards).toBundle();
startActivity(intent, translateBundle);
dialog.dismiss();
finish();
} else {
startActivity(intent);
dialog.dismiss();
finish();
}
dialog.show();
}
Upvotes: 1
Views: 2231
Reputation: 6828
Try this,
public void show(){
final Dialog dialog = new Dialog(invoice.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.popup);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = Math.round((width * 10) / 15);
lp.height = Math.round(height / 3);
dialog.getWindow().setAttributes(lp);
dialog.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(invoice.this, First_grid.class);
intent.putExtra("yo", 0);
if (Build.VERSION.SDK_INT >= 16) {
//The code below is for the cool transition effect that happens once the player clicks the play button..!
Bundle translateBundle = ActivityOptions.makeCustomAnimation(
invoice.this,
R.anim.activity_slide_up,
R.anim.activity_slide_out_upwards).toBundle();
startActivity(intent, translateBundle);
dialog.dismiss();
finish();
} else {
startActivity(intent);
dialog.dismiss();
finish();
}
}
}, 4000);
}
Upvotes: 1