Hardware Backkey

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Hardware Backkey

Post by saviour » Wed Mar 05, 2014 3:04 am

Hi there,

I referred to browser sample lesson. I have app with two card- one with button and another has "browser" group. Well, I know, back key can be assigned two functionalities-
1. "retreat" inside the browser to go to previous page
2. "go recent or back" to go to card that opened the browser.

My question is can I create if /else function so that the back button retreat inside the browser and go to first card if it reaches the top page or layer, whatever, of the browser like this:

on backkey
If on the top layer of the group "browser" than <------This is wrong :D Need correct code here
go recent
else doAction "retreat"
end backkey

Please help.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Hardware Backkey

Post by Simon » Wed Mar 05, 2014 4:34 am

Hi saviour,
If I understand your question correctly.

I'm thinking you are going to have to watch that browserStartedLoading has started after doAction "retreat".
When you reach the initial page browserStartedLoading isn't triggered.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Re: Hardware Backkey

Post by saviour » Wed Mar 05, 2014 4:51 am

Hi Simon,

Thanks.

You always come to rescue. Yeah..its like that. Inside the browser, I want back key to "retreat" all the way to firstmost webpage and after reaching the first page, move to "recent" card. Having only "doAction retreat" code in back key will take only to firstmost page then it stucks. So please help. :D

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Hardware Backkey

Post by Simon » Wed Mar 05, 2014 5:40 am

OK I have something working.
Add a global gEnd and in the browserStartedLoading set the global to true.

Code: Select all

on backKey
   put false into gEnd
   doAction "retreat"
   send firstPage to me in 250 millisec
end backKey

on firstPage
   if gEnd= false then
      go cd 2
   end if
end firstPage
See how that works?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Re: Hardware Backkey

Post by saviour » Wed Mar 05, 2014 3:08 pm

Thanks Again..

Now tried it..it is not working, fully :D
With above script, backkey will take me to card 2 direct from the browser. While changing the portion of the same. as below, I can roam within the browser but cannot exit to card 2.-
on firstPage
if gEnd= true then
go cd 2
end if
end firstPage

I also tried these:

(1)on backKey
if gEnd= false then
doAction "retreat"
else go cd 2
end backKey (result is goes to card 2)

(2)on backKey
if gEnd= true then
go cd 2
else doAction "retreat"
end backKey (result is retreat within the browser )

Can u please look what is going wrong here??? Thanks..

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Hardware Backkey

Post by Klaus » Wed Mar 05, 2014 3:42 pm

You never put any VALUE into gEnd in all of your 3 scripts!?
So gEnd is never TRUE or FALSE!

Better read Simons script again :D

saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Re: Hardware Backkey

Post by saviour » Wed Mar 05, 2014 8:17 pm

Well I tried many variations but could not succeed. Please help.

on browserStartedLoading pUrl
set the gEnd of me to "home"
end browserStartedLoading

on backKey
if gEnd is not "home" then
doAction "retreat"
send firstPage to me in 250 millisec
end if
end backKey

on firstPage
if gEnd is not "home" then
go cd 2
end if
end firstPage

well I always end up in card 2 :D

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Hardware Backkey

Post by Simon » Wed Mar 05, 2014 8:20 pm

You forgot to set gEnd to something else in backKey.
The browserStartedLoading is correct.

Simon
Edit; Also you are using a custom property, you have to state "of me" each time it's called.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

saviour
Posts: 26
Joined: Wed Feb 05, 2014 5:11 am

Re: Hardware Backkey

Post by saviour » Thu Mar 06, 2014 5:03 am

Thanks guys. I tried, even in many variations of scripts, but I think it is not doable.

on browserStartedLoading pUrl
set the gEnd of me to "home"

By setting above variable, whenever a new webpage opens within old webpage, above variable is set to true. So backkey either functions as "retreat" when variable is set to true or functions "go cd2" when it is set to false. So it is not working.

May be by putting some check (like creating a global variable) at the time when card opens the browser group (webpage) helps!!! I am just learning :oops:, so can it done like that ??

Thanks!!!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Hardware Backkey

Post by Simon » Thu Mar 06, 2014 5:10 am

Hey saviour,
You really are ignoring the first line of on backKey.
Why did I write that?
What does it do?
What will change that cp or var back to a different state?

Simon
Edit, I have tested this and it is working.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply