back key event

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

back key event

Postby ansh.chauhan » Mon Jun 02, 2008 1:01 pm

hey buddy,

i m getting a problem in back keyevent....method i m using is this

public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
}
}

when i click on back....it goes to my back screen after that i goes to the mainmenu
i dont kno y this happening
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Top

Postby ansh.chauhan » Mon Jun 02, 2008 1:07 pm

here mainmenu is the menu screen of the emulator
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Postby mathiastck » Wed Jun 04, 2008 12:20 am

I'm not sure what your question is, but it's important whether you return True or False from the method. To quote the doc:

"If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false."

http://code.google.com/android/referenc ... w.KeyEvent)
mathiastck
Freshman
Freshman
 
Posts: 6
Joined: Wed Feb 06, 2008 12:47 am

Postby cadlg » Wed Jun 04, 2008 1:30 am

Hi guys.

Some time ago I was trying to handle the "back" key event, but it doesn't work as expected.
It continues propagating wheather you return true or false.

I think "home" and "back" key events cannot currently be managed this way... :?

Regards,

cadlg
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

Postby mathiastck » Wed Jun 04, 2008 1:54 am

cadlg wrote:Hi guys.

Some time ago I was trying to handle the "back" key event, but it doesn't work as expected.
It continues propagating wheather you return true or false.

I think "home" and "back" key events cannot currently be managed this way... :?

Regards,

cadlg


No you can override the back key. I just reran my code and it still works as expected. I have an application with a webview, I wanted to override the back key in the case there were pages to go back, and otherwise to close the activity as normal. Here is said code:

public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_BACK){
if(ourWebview.canGoBack()){
ourWebview.goBack();
return true;
}else{
return super.onKeyDown(keyCode, event);
}
}
return super.onKeyDown(keyCode, event);
}
mathiastck
Freshman
Freshman
 
Posts: 6
Joined: Wed Feb 06, 2008 12:47 am

Postby ansh.chauhan » Wed Jun 04, 2008 8:16 am

thanx dude no its working..but i hav one more problem
onDownKey event is not working with textview
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Top

Postby cadlg » Wed Jun 04, 2008 4:50 pm

My mistake. :shock:

I reviewed my test program, and the non-working keys were KEYCODE_HOME and KEYCODE_ENDCALL.

I'm glad you replied, and thus my mistake was clarified.

ansh.chauhan: Are you overriding the textview's onKeyDown method and it's not working ? if so, remember that your view has to be focussed so that it can receive the key event...

regards,

cadlg
cadlg
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Wed Feb 20, 2008 12:33 am
Location: Guatemala

this is my code

Postby ansh.chauhan » Thu Jun 05, 2008 5:43 am

public class DisplayData extends TextView{
MainMenu mainMenu;
OnKeyListener keyListener;
public DisplayData(Context context) {

super(context);
Log.v("11111","111111111");
this.append("nnn"+AppConstant.title+":-");
this.append("nn"+AppConstant.data);
InfotainmentActivity.activity.setContentView(this);
this.setOnKeyListener(keyListener);
// TODO Auto-generated constructor stub
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if(keyCode==KeyEvent.KEYCODE_BACK){
Log.v("2222","22222222");
mainMenu.STATUS=AppConstant.STATUS_SUNSIGN;
InfotainmentActivity.activity.setContentView(mainMenu);
return true;

}
return super.onKeyDown(keyCode, event);
}


}
ansh.chauhan
Experienced Developer
Experienced Developer
 
Posts: 75
Joined: Tue May 27, 2008 7:04 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests