0

Possible Duplicate:
onKeyDown() or onBackPressed()

I don't know what is wrong, but whenever I click on the android mobile back it goes directly to the login screen. Control is not going inside this method. I want to give same functionality to mobile back button which I am providing to my application back button. Here is my code ...

@Override
public void onBackPressed() 
{
    Intent edit = new Intent(getParent(), CreatePing.class);
    TabGroupActivity parentActivity = (TabGroupActivity)getParent();
    parentActivity.startChildActivity("My Pings", edit);
}
Community
  • 1
  • 1
user1249134
  • 165
  • 1
  • 1
  • 7

1 Answers1

0

I think you can do this in your code.

@override
public boolean dispatchKeyEvent(KeyEvent event) {
   if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
    Intent edit = new Intent(getParent(), CreatePing.class);
    TabGroupActivity parentActivity = (TabGroupActivity)getParent();
    parentActivity.startChildActivity("My Pings", edit);
    return true;
  }
   return super.dispatchKeyEvent(event);
}
5hssba
  • 8,079
  • 2
  • 33
  • 35
  • Thank-you Raju But still control is not going inside this method no effect of back button click on this method ...u send me sample project or some thing like that ???? – user1249134 Mar 09 '12 at 10:15
  • can you paste your code here? – 5hssba Mar 09 '12 at 10:19
  • i am doing same thing which u said ... – user1249134 Mar 09 '12 at 10:24
  • ok can u give me ur email id ..here i can not post complete code – user1249134 Mar 09 '12 at 10:29
  • ok i sent u please check once – user1249134 Mar 09 '12 at 10:34
  • @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { Log.d("Debug","insssside backkkkkkkkkkkkkkkkkkkkk butonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); Intent edit = new Intent(getParent(), CreatePing.class); TabGroupActivity parentActivity = (TabGroupActivity)getParent(); parentActivity.startChildActivity("My Pings", edit); return true; } – user1249134 Mar 13 '12 at 06:12
  • hello friends this code is working some times and some times it is not ....can any body is here who faced the same problem with clciking on back button of device... – user1249134 Mar 13 '12 at 06:14