# How to click on home back and recent button in android?

**URL:** <https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348>\
**Category:** Support\
**Created:** [March 13, 2015, 4:31am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348 "2015-03-13T04:31:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhanvam](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/9fc29f/32.png) [@sudhanvam](https://discuss.appium.io/u/sudhanvam)\
**Post date:** [March 13, 2015, 4:31am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/1 "2015-03-13T04:31:39Z")

</div>

![](https://discuss.appium.io/uploads/default/770/a7f0e0ea672f0516.jpg)

please help me to click on these buttons…

thanks in advance.

regards,  
Sudhanva.M

---

<div class="post-metadata">

**Author:** ![willosser](https://discuss.appium.io/user_avatar/discuss.appium.io/willosser/32/2454_2.png) [@willosser](https://discuss.appium.io/u/willosser)\
**Post date:** [March 13, 2015, 2:22pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/2 "2015-03-13T14:22:09Z")

</div>

You can simulate pressing these keys using the appium driver’s press\_keycode method, which calls adb’s “input keyevent”, shown here in Ruby

```
appium_driver.driver.press_keycode <keycode>

```

Back is 4  
Menu is 82  
Recent Apps is 187 (APP\_SWITCH)

You can find the full list of keycodes here:  
[http://developer.android.com/reference/android/view/KeyEvent.html](http://developer.android.com/reference/android/view/KeyEvent.html)

---

<div class="post-metadata">

**Author:** ![pendu\_adi](https://discuss.appium.io/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@pendu\_adi](https://discuss.appium.io/u/pendu_adi)\
**Post date:** [April 21, 2016, 1:05pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/3 "2016-04-21T13:05:02Z")

</div>

Hi Can you help with the above code

appium\_driver.driver.press\_keycode

in Java

---

<div class="post-metadata">

**Author:** ![willosser](https://discuss.appium.io/user_avatar/discuss.appium.io/willosser/32/2454_2.png) [@willosser](https://discuss.appium.io/u/willosser)\
**Post date:** [April 21, 2016, 3:02pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/4 "2016-04-21T15:02:41Z")

</div>

appium\_driver.driver.pressKeyCode

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [April 21, 2016, 3:15pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/5 "2016-04-21T15:15:11Z")

</div>

```auto
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.BACK);
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.HOME);

```

---

<div class="post-metadata">

**Author:** ![pendu\_adi](https://discuss.appium.io/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@pendu\_adi](https://discuss.appium.io/u/pendu_adi)\
**Post date:** [April 22, 2016, 5:41am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/6 "2016-04-22T05:41:13Z")

</div>

the driver which i am using is of AndroidDriver so i guess there is no need to type cast that.  
Any which ways the ide is not prompting me with pressKeyCode method 😓

---

<div class="post-metadata">

**Author:** ![pendu\_adi](https://discuss.appium.io/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@pendu\_adi](https://discuss.appium.io/u/pendu_adi)\
**Post date:** [April 22, 2016, 6:39am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/7 "2016-04-22T06:39:56Z")

</div>

I got the solution for the same driver.sendKeyEvent(keycode) for menu button the key code is 82 😃

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [April 22, 2016, 6:57am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/8 "2016-04-22T06:57:18Z")

</div>

the same is:

```auto
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.KEYCODE_MENU);

```

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [April 22, 2016, 7:19am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/9 "2016-04-22T07:19:17Z")

</div>

> [@pendu\_adi](#):
>
> Any which ways the ide is not prompting me with pressKeyCode method

your java-client is old version 🙂

---

<div class="post-metadata">

**Author:** ![Suraj786](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/bc8723/32.png) [@Suraj786](https://discuss.appium.io/u/Suraj786)\
**Post date:** [August 26, 2016, 12:12pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/10 "2016-08-26T12:12:05Z")

</div>

How to press the same in C#… I tried but not able to find any near function to above solutions!!! Help will be appreciated.

---

<div class="post-metadata">

**Author:** ![willosser](https://discuss.appium.io/user_avatar/discuss.appium.io/willosser/32/2454_2.png) [@willosser](https://discuss.appium.io/u/willosser)\
**Post date:** [August 26, 2016, 4:09pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/11 "2016-08-26T16:09:56Z")

</div>

> <https://github.com/appium/appium-dotnet-driver/blob/a903187f09ae0151fafe4f217b3c6ca4e3441604/appium-dotnet-driver/Appium/Android/Interfaces/ISendsKeyEvents.cs>

---

<div class="post-metadata">

**Author:** ![shijukonline](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@shijukonline](https://discuss.appium.io/u/shijukonline)\
**Post date:** [October 10, 2016, 11:50pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/12 "2016-10-10T23:50:55Z")

</div>

Python code for hardware back button  
driver.press\_keycode(4)

---

<div class="post-metadata">

**Author:** ![crujzo](https://discuss.appium.io/letter_avatar_proxy/v4/letter/c/5f8ce5/32.png) [@crujzo](https://discuss.appium.io/u/crujzo)\
**Post date:** [October 25, 2016, 6:59am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/13 "2016-10-25T06:59:25Z")

</div>

driver.navigate().back(); works perfectly for me

---

<div class="post-metadata">

**Author:** ![ranjith\_hs](https://discuss.appium.io/letter_avatar_proxy/v4/letter/r/8dc957/32.png) [@ranjith\_hs](https://discuss.appium.io/u/ranjith_hs)\
**Post date:** [March 2, 2017, 6:16am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/14 "2017-03-02T06:16:46Z")

</div>

> [@crujzo](#):
>
> driver.navigate().back();

This is fine to navigate back…but if i want to click on CAMERA button  
pressKeyCode is not working for me even after using java client 5.0  
please let me know if someone has implemented the same.

---

<div class="post-metadata">

**Author:** ![crujzo](https://discuss.appium.io/letter_avatar_proxy/v4/letter/c/5f8ce5/32.png) [@crujzo](https://discuss.appium.io/u/crujzo)\
**Post date:** [March 7, 2017, 3:25am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/15 "2017-03-07T03:25:13Z")

</div>

Hello @ranjith_hs,  
Which Event Number you are using?

---

<div class="post-metadata">

**Author:** ![ranjith\_hs](https://discuss.appium.io/letter_avatar_proxy/v4/letter/r/8dc957/32.png) [@ranjith\_hs](https://discuss.appium.io/u/ranjith_hs)\
**Post date:** [March 7, 2017, 6:28am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/16 "2017-03-07T06:28:02Z")

</div>

I was using appium java client 3.4.1 with SendKeyEvent

now that i am not able to use **PressKeyCode** with 3.4.1

---

<div class="post-metadata">

**Author:** ![viswesvar](https://discuss.appium.io/letter_avatar_proxy/v4/letter/v/aca169/32.png) [@viswesvar](https://discuss.appium.io/u/viswesvar)\
**Post date:** [December 29, 2017, 4:10pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/17 "2017-12-29T16:10:34Z")

</div>

Hi willosser,  
I’m new to Appium, I have the same question how to use the return button in Ruby, I already tried _driver.sendKeyEvent(4)_ but it gives me error. can you help me with this

> undefined local variable or method `appium\_driver’

---

<div class="post-metadata">

**Author:** ![willosser](https://discuss.appium.io/user_avatar/discuss.appium.io/willosser/32/2454_2.png) [@willosser](https://discuss.appium.io/u/willosser)\
**Post date:** [January 29, 2018, 5:51pm UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/18 "2018-01-29T17:51:54Z")

</div>

Hi Viswesvar,

You’ll have to provide a bit more information, such as your code.

I’m guessing that you expect the object appium\_driver to be your appium driver. Where did you set that?

---

<div class="post-metadata">

**Author:** ![Prarna](https://discuss.appium.io/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@Prarna](https://discuss.appium.io/u/Prarna)\
**Post date:** [May 28, 2018, 6:41am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/19 "2018-05-28T06:41:32Z")

</div>

> [@Aleksei](#):
>
> ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.BACK);

I am using the above code but its not working for me.

---

<div class="post-metadata">

**Author:** ![suban](https://discuss.appium.io/user_avatar/discuss.appium.io/suban/32/5497_2.png) [@suban](https://discuss.appium.io/u/suban)\
**Post date:** [July 13, 2018, 5:07am UTC](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348/20 "2018-07-13T05:07:03Z")

</div>

since pressKeyCode has been depreciated you can use

```
    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.MobileElement;
    import io.appium.java_client.android.AndroidDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import io.appium.java_client.android.nativekey.AndroidKey;
    import io.appium.java_client.android.nativekey.KeyEvent;
   
     //initialize AppiumDriver and DesiredCapabilities

     ((AndroidDriver<MobileElement>) driver).pressKey(new KeyEvent(AndroidKey.HOME));
     ((AndroidDriver<MobileElement>) driver).pressKey(new KeyEvent(AndroidKey.APP_SWITCH));
```

[Next page](https://discuss.appium.io/t/how-to-click-on-home-back-and-recent-button-in-android/3348.md?page=2)
