I have a custom alert. I made a custom layout for it and a class that extends Dialog where i have several functions defining alert's behavior. I call that custom alert from an activity, by clicking on a button.
Everything works fine until I want to ADD handler.postDelayed to the Dialog.
Here is a bit of code from my Dialog class:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.bonus_dialog);
handler.postDelayed(tickOne, 900);
handler.postDelayed(tickTwo, 1800);
}
Here is tickOne runnable:
Runnable tickOne = new Runnable() {
@Override
public void run() {
countdown.setText("00:04");
}
};
tickTwo method is the same, only setting another text.
When the app crashes it shows an error in the activity from where I call the Dialog, and I trace the error back to this line:
dialog.show();
I figured out that if i comment handler.postDelayed methods, my dialog will be shown and disappear as intended.
So, my question is - why isn't postDelayed method supported in custom dialogs and how can I go around this?