Android Question [B4xPages] How to always run a procedure when starting the program?

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I need to run something whenever the program starts.
In the "Created" it runs the first time, if I close the program and reopen it, it doesn't run.
In the "Appair" it is not valid because it is executed when the page changes and returns to the first one.
Where do I put it?
It is to ask for a password, show a splash, etc.
In B4XMainPage I can't find the solution.
Do I put the code in the "Activiy Main"?
Thank you.
 

vecino

Well-Known Member
Licensed User
Longtime User
I need it to ask for the password every time it starts. Users are salespeople / representatives / commercials who travel to customers' stores and usually take an order, exit the application, and return to make a query, take note of another item that the customer has ordered at the last minute, etc.
If it doesn't ask for a password then it's a great open door to anyone taking control of the tablet. That is why I need it to ALWAYS ask for the password as soon as the application starts.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
With the traditional "Activity" method there was no problem, it always went through "Create" when starting.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Ok but then there seems to be no solution to always run something every time a b4xpage app is started :/
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Ok but then there seems to be no solution to always run something every time a b4xpage app is started :/
You're making me angry

What do you want to achieve? What do you mean with "every time an app is started"?

I attached an example on how to do it, but probably you want a group of lines (a routine) to run every time your app is brought to foreground and not really every time it starts when the app has been "permanently" stopped-killed.

If so, you can do it by adding this code to each page:
B4X:
Private Sub B4XPage_Foreground
    B4XPages.ShowPage("pagLogin")
End Sub
or
B4X:
Private Sub B4XPage_Foreground
    B4XPages.MainPage.DoSomething
End Sub
where DoSomething is a public sub of B4XMainPage and that can include also code to show the B4XMainPage itself.





Otherwise...

?
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Sorry for my explanation, but the "google translator" can no longer.

Basically, what I want is that it always asks for the password when starting the application.
If the user chooses "Exit" of the application and clicks the icon again to start it, it will ask for the password again. That's it.

Anyway, I thank you and the colleagues who have intervened, of course, for the time and effort dedicated.
Many thanks.

PS: I'm going to try "Foreground", to see if it works for me.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
If the user chooses "Exit" of the application
This is the question: what you mean talking of "exit".

Usually Android apps does not have a button to "exit app"; the user presses the back key, which does not really closes the app, send it to background.
When the user taps the app icon, it becomes active again, return to foreground; only if in the meantime the operating system has killed it does it start from scratch, let's say.

So, the example I attached to post #18 is what you need.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I hadn't seen this post.

Ok, then the solution of the B4XPage_Foreground event is fine.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…