In activity's onCreate(), I arm a TimerTask that should display a dialog after 10 secs :
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
Looper.prepare();
Toast.makeText(getApplicationContext(), "Test", Toast.LENGTH_LONG).show();
Log.i(this.getClass().getName(), "Dialog should be displayed...");
new AlertDialog.Builder(MainActivity.this)
.setTitle("TEST")
.setMessage("This is a test")
.show();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 10000);
}
When this activity is created, the Toast is displayed after 10 secs, but not the dialog. Any idea why ?
I'm compiling using Android SDK 33.