Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to handle BackButton in Android Devices


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Mar 2, 2016 4:02 PM Last Post By: Victor Zepeda
Victor Zepeda

Posts: 20
Registered: 3/22/16
How to handle BackButton in Android Devices  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 2, 2016 12:32 PM
Im using XE8 c++ builder. i check some snippets and i tried to implement the next code:

void __fastcall TPrincipal::FormKeyUp(TObject *Sender, WORD &Key, System::WideChar &KeyChar,
TShiftState Shift)
{
#ifdef ANDROID
if (Key == vkHardwareBack)
Key = 0;
#endif
}

I only test with a Xperia Z1 and it doesn´t work!

Any idea of what is happening?
Appears this issue only in Xperia Z1??

Greetings
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to handle BackButton in Android Devices  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 2, 2016 12:50 PM   in response to: Victor Zepeda in response to: Victor Zepeda
Victor wrote:

I only test with a Xperia Z1 and it doesn´t work!

Define "does't work". Is the OnKeyUp event being fired at all? If so, what
are the actual values of the Key and KeyChar parameters?

--
Remy Lebeau (TeamB)
Victor Zepeda

Posts: 20
Registered: 3/22/16
Re: How to handle BackButton in Android Devices  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 2, 2016 3:34 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Victor wrote:

I only test with a Xperia Z1 and it doesn´t work!

Define "does't work". Is the OnKeyUp event being fired at all? If so, what
are the actual values of the Key and KeyChar parameters?

--
Remy Lebeau (TeamB)

the event is fired but the code inside #ifdef ANDROID is not executed

when i remove the line #ifdef ANDROID the portion of code works.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to handle BackButton in Android Devices  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 2, 2016 3:56 PM   in response to: Victor Zepeda in response to: Victor Zepeda
Victor wrote:

the event is fired but the code inside #ifdef ANDROID is not executed

when i remove the line #ifdef ANDROID the portion of code works.

The problem is that your #ifdef is looking for the wrong conditional. The
correct conditional in C++ is "__ANDROID__", not "ANDROID" (that is what
the Delphi compiler defines). This is documented:

http://docwiki.embarcadero.com/RADStudio/Seattle/en/Predefined_Macros

http://docwiki.embarcadero.com/RADStudio/Seattle/en/BCCAARM

So you need to change your code accordingly:

void __fastcall TPrincipal::FormKeyUp(TObject *Sender, WORD &Key, System::WideChar 
&KeyChar, TShiftState Shift)
{
    #ifdef __ANDROID__
    if (Key == vkHardwareBack)
        Key = 0; 
    #endif
}


--
Remy Lebeau (TeamB)
Victor Zepeda

Posts: 20
Registered: 3/22/16
Re: How to handle BackButton in Android Devices  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 2, 2016 4:02 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Victor wrote:

the event is fired but the code inside #ifdef ANDROID is not executed

when i remove the line #ifdef ANDROID the portion of code works.

The problem is that your #ifdef is looking for the wrong conditional. The
correct conditional in C++ is "__ANDROID__", not "ANDROID" (that is what
the Delphi compiler defines). This is documented:

http://docwiki.embarcadero.com/RADStudio/Seattle/en/Predefined_Macros

http://docwiki.embarcadero.com/RADStudio/Seattle/en/BCCAARM

So you need to change your code accordingly:

void __fastcall TPrincipal::FormKeyUp(TObject *Sender, WORD &Key, System::WideChar 
&KeyChar, TShiftState Shift)
{
    #ifdef __ANDROID__
    if (Key == vkHardwareBack)
        Key = 0; 
    #endif
}


--
Remy Lebeau (TeamB)

Thank You for your answer!!!!

Greetings!!!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02