Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need help with Android and Java

Tags:

java

android

I am struggling to figure out how to handle a situation in Android where code continues to execute when I really don't want it to. In the onCreate() of an activity I have some stuff that I need to do in order and I can't have the code continue to execute until certain things happen first. I understand that this is how Android and Java behave and I am struggling to figure out another way to accomplish what I need.

ShowEula is a class that I created to show a simple dialog with my EULA. I really need to wait until the user agrees or disagrees with the EULA before calling DBGetOnlineVersionNumber(). Maybe I'm just not going this the correct way. Anyway here's a snippet of my code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    setContentView(R.layout.main);
    String version;
    ShowEula();     
    version = DBGetOnlineVersionNumber();
    ....
like image 495
Michael Little Avatar asked Feb 13 '26 16:02

Michael Little


1 Answers

You need to rethink things in terms of the event-driven model used by android.

You cannot wait for UI events in onCreate, because no UI events can be delivered until after onCreate has returned.

Perhaps you could organize things as a software state machine.

onCreate would show the EULA and set the state to EULA_SHOWING

accept would advance the state to EULA_ACCEPTED and display something next

Of course you probably don't want to show the EULA on every startup, but only after install, but you can handle this with something stored in settings.

like image 169
Chris Stratton Avatar answered Feb 15 '26 04:02

Chris Stratton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!