DuyguK
DuyguK

Reputation: 4300

How can i use real back button functionallty in my back button programmatically?

i want to create a button which works like a real back button.When i press the back button(my button) this is work same with real button.How can i do programmatically?

Upvotes: 1

Views: 1824

Answers (2)

fr4n
fr4n

Reputation: 755

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {       
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

Upvotes: 0

theomega
theomega

Reputation: 32031

Call onBackPressed() [docs] in the onClick handler of your button.

For example, use:

  button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 onBackPressed();
             }
         });

Upvotes: 5

Related Questions