Android Question How to display another activity when "Main" activity first runs?

JohnC

Expert
Licensed User
Longtime User
I have the "Main" activity as my app's activity.

But, I want to display a "Terms and conditions" activity (and it needs to be an activity) right when the main activity is first loaded after installing my app.

And if the user declines my app's ToS, I want to close the app fully.

I was thinking of simply doing this:

B4X:
'(Main Activity)
Sub Activity_Create (FirstTime as Boolean)

    If PrefManager.GetBoolean("TOCAccepted") = False then
       StartActvity("toc")
       Return
    End if

    If FirstIime = True
      Activity.Loadlayout("main")
    End if

    'other code here

End Sub

'(this sub is also in the main activity)
Sub ExitApp
  
    Activity.Finish
    ExitApplication  
  
End Sub

----------------

'(Then in the TOC activity I would have this code execute if the user declined my TOC)

Sub cmdDecline_Click
     CallSubDelayed(main,"exitapp")
     Activity.Finish
End Sub

So would events happen in the sequence as I am expecting:

1) The main activity will not run most of the activity_create sub and just "chill" while the TOC activity is shown
2) Then after the TOC activity closes itself, the ExitApp routine will run and the app will gracefully close down.

Or will there be some async issues that could be unpredictable with this method?
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Is there a reason for this?
and it needs to be an activity
Otherwise you will need only a full screen panel shown in the Main, with "Terms and conditions" and buttons (if "accepted", hide or remove the panel, else exit app).


If PrefManager.GetBoolean("TOCAccepted") = False then
I hope that this data is not easily accessible.


If FirstIime = True
Activity.Loadlayout("main")
End if
This is wrong, you will need to load the layout also after first time.


Why don't use the Main Activity "as toc" and if terms are accepted start a second Activity which acts "as Main"?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Understood about needing to still load in the main activity layout before showing the TOC activity.

Thanks for the info and suggestion.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…