Android Question Problem With Webview And Backbutton

Inven

New Member
Hello i am newbie ;) this week installed b4a and starting .

I added Webview then when i click on Back button get exit from application

i tested this code's

& now i have question

My webview is only online and have many pages and i want

when user in sub pages back button redirect to home
subpage => mainpage

when user in homepage back button exit application
homepage => exitapplication

example Url (as homepage) :

webview.loadurl("https://simple.com")
 

drgottjr

Expert
Licensed User
Longtime User
in theory you can direct the user wherever you want if you know the url of the
page she's looking at in the webview.

you add an activity keypress sub, which tells you the key that was tapped.
if it was the back key, you do your logic to decide where to direct the user.
make sure to add "return true" when you're done.

i'm guessing that the user if free to follow links in the webview, yes? if this is the case, then you
have no idea what's on the page.

you need the page to tell you. webview.url should tell you that. try it. there are a couple
other options, but this is the most direct. give it a good workout before assuming it's
doing what you want every time it's called.


so, user presses back key, this triggers activity.keypress, you query webview.url which tells you
where the user is. if it's the home page, you close the app. if not, you do whatever. return true
 
Last edited:
Upvote 0
Top