BackKey: best way to use it

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
trevix
Posts: 581
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

BackKey: best way to use it

Post by trevix » Thu Sep 17, 2020 10:27 am

In my standalone I have several "Return" buttons that navigate to the previous card, while holding a script that, for example, save new settings or else.
For example, in card B there is a button "return" that go to card A after having saved something and set some stuff on card A before showing.

Coming from iOS I didn't realise how Android users count on the physical Backkey of their device.
I am now trying to find the best way to implement this all over my stack.

As I understand the

Code: Select all

on BackKey
...(1) eventually do something, like saving and going to previous card
--do not pass otherwise the standalone exits
end backer
must be put on each card script. Since the code (1) is already on the mouseUp script of the button ("return"),I would like to hold this script in a single place, without duplicating it. I was wondering if the script below (that works) is the best way to do it (without having to put a
send "Mouseup" to btn return of card B
(that doesn't sound the best way since I have already "send" and "cancel" all over the standalone.

Card B script:

Code: Select all

On Backkey
set the FireBackKey of btn "return" of this card to empty
end Backkey
Btn "return" script:

Code: Select all

On Mouseup
put true into gSetting
set the backcolor of rect "X" of card "A" to red
go card "A"
End Mouseup

SetProp FireBackKey
Mouseup
end FireBackKey
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

trevix
Posts: 581
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: BackKey: best way to use it

Post by trevix » Thu Sep 17, 2020 12:14 pm

Thinking of it, I may have to rewrite all navigation of my stacks.
This one could be a better solution.
card B script:

Code: Select all

On Backkey --the actual navigation
put true into gSetting
set the backcolor of rect "X" of card "A" to red
go card "A"
end Backkey
The navigation "return" button script of card B:

Code: Select all

On Mouseup
Backkey
end Mouseup
Before I rewrite the all stack, is this the correct solution?
Trevix
OSX 10.14.6 LC 9.6.0 Dp2 iOs 9.3>

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5792
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: BackKey: best way to use it

Post by jacque » Thu Sep 17, 2020 5:51 pm

You're right, the back key is essential for Android users. There's nothing wrong with using "send" which is how I usually do it. If all your back navigation always goes to the same place then you don't need send, but in my apps the Back button is usually specific to the card.

The handler is very simple in that case, and can go in the stack script or a background group script:

Code: Select all

on backkey
  if there is a button "back" of this card
  then send "mouseUp" to button "back" of this card
end backkey
If the Back button always goes to the same place then all you need is:

Code: Select all

on backkey
  go card "A" 
end backkey
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Android Deployment”