I am new to Android and this is my first question here so please go easy on me.
Is it possible to check some condition inside onCreate() of an Activity and display an AlertDialog?
I am creating an AlertDialog anonymously in Oncreate() and calling show on that instance but the AlertDialog is never displayed.
You can add an icon with the following code: Dialog dialog = new Dialog(context); dialog. requestWindowFeature(Window. FEATURE_LEFT_ICON); dialog.
OnCreate is only called once.
Showing an alert dialog in onCreate causes android.view.WindowLeaked exception, because the activity isn't yet created.
The solution I found is to put the code that shows the dialog in onStart() method:
@Override
protected void onStart() {
super.onStart();
// show dialog here
}
It is definitely possible, try this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Stackoverflow!").create().show();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With