Search code examples
androiddelayandroid-alertdialogoncreate

How to delay an activity until user accept alert dialog


I have an quiz app. and i want the user to choose the type of questions from alert dialog . so the alert dialog has a check boxes buttons so if the user can select more then on type. when the user click the positive button in alert dialog it will send info to if condition then the condition will filter the questions and then will pass it to an array. the problem is the array its inside oncreate and i want the alert dialog to be in same class so when i run the class oncreate will start and i get null exception because i didn't pass any info to the array. How can i delay oncreate() and make it load only after the user click on positive button of alert dialog. The alert dialog will be in same class . So how can i do it ? is it possible? and thanks.


Solution

  • onCreate() is the first called when the activity is created per the android activity lifecycle so, no. I'm not sure why you would want it in the same activity if you don't want it to start unless they click 'OK'. Put it in it's own class or the previous activity.