Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Development

Reply
Highlighted
Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Functionality For Home Button in Android Development

Hello,

I have developed BlackBerry Application for 9800 Torch using Java as a nativ language in which i have performed functionality of Emergency Exit on Red button,sample code is given below:

protected boolean keyDown(int keycode, int time)
{
if (keycode == 1179648)
{
if(Dialog.ask(4, "Emergency Exit") == Dialog.OK)
{
System.exit(0);
}
}
else
{
return super.keyDown(keycode, time);
}
return true; 
}


In the same way i want to perform functionality on Home Button for "Emergency Exit" in android, but the home button is not performing there, for system.exit(0);  I want to make Emergency Exit on any screen by pressing Home Button, but it is not working.. Please ANy one give me a hint or a sample code....Please....

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_HOME) {
Toast.makeText(getApplicationContext(),"Home", Toast.LENGTH_LONG).show();

System.exit(0);
}
return super.onKeyDown(keyCode, event);
}



Retired
Posts: 264
Registered: ‎01-08-2013
My Device: BlackBerry 10 Dev Alpha B
My Carrier: Bell

Re: Functionality For Home Button in Android Development

Hey there,

 

Could you elaborate on what you mean when you say that it is not working?

 

Is it not reaching your code, is the KeyCode different than expected, does System.exit() not close your app, etc.

 

Thanks,

 

    Jusitn

Justin Jasmann | Android Application Development Consultant
Developer Relations
developer.blackberry.com
Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Re: Functionality For Home Button in Android Development

Thanks For You Reply..

Actually the problem is, System.exit(0); is not working with Home Button.. I am making an aaplication in which first of all i have to Login then after that if on any Screen I press Home Button then it should properly exit my application... I am using system.exit(0); in BB it is working fine, but i want to use it in ANDROID... Kindly plx help me out...

Developer
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: Functionality For Home Button in Android Development

Hi musmankhan90,

 

This is not aright place to learn Android. Its for troubleshoot Android Porting. Make sure your applicatio is functioning fine in Android device and then proceed further.

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Retired
Posts: 264
Registered: ‎01-08-2013
My Device: BlackBerry 10 Dev Alpha B
My Carrier: Bell

Re: Functionality For Home Button in Android Development

I agree with kayaksony. Stackoverflow may better suit your needs for learning pure Android development.

 

Regardless, I may question the intentions of what you are trying to accomplish. 

 

The default behaviour of the HOME button cannot be overridden in Android.

 

Source: http://stackoverflow.com/questions/4783960/call-method-when-home-button-pressed-on-android

 

    Justin

Justin Jasmann | Android Application Development Consultant
Developer Relations
developer.blackberry.com