# Android back button - code

**URL:** <https://forum.ionicframework.com/t/android-back-button-code/4545>\
**Category:** ionic-v1\
**Created:** [May 20, 2014, 5:04pm UTC](https://forum.ionicframework.com/t/android-back-button-code/4545 "2014-05-20T17:04:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jana](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@Jana](https://forum.ionicframework.com/u/Jana)\
**Post date:** [May 20, 2014, 5:04pm UTC](https://forum.ionicframework.com/t/android-back-button-code/4545/1 "2014-05-20T17:04:59Z")

</div>

Hi Ionic Folks ! ,

I’m really struck at the android back functionality. If anyone could post a demo on codepen , it would be helpful .

Even if thats listed under the docs it will be helpful for the beginners…

Cheers , So far loving the ionicframework

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [May 20, 2014, 10:16pm UTC](https://forum.ionicframework.com/t/android-back-button-code/4545/2 "2014-05-20T22:16:12Z")

</div>

You could do something like this

```
.controller('MyCtrl', function($scope, $ionicPlatform) {
   $ionicPlatform.onHardwareBackButton( function(){
    // Your function here
   })

   //or 

$ionicPlatform.registerBackButtonAction(function () {
  if (condition) {
    navigator.app.exitApp();
  } else {
    handle back action!
  }
}, 100)
    });

```

Check out the docs.

[http://ionicframework.com/docs/api/service/$ionicPlatform/](http://ionicframework.com/docs/api/service/%24ionicPlatform/)

---

<div class="post-metadata">

**Author:** ![Jana](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@Jana](https://forum.ionicframework.com/u/Jana)\
**Post date:** [May 21, 2014, 2:25am UTC](https://forum.ionicframework.com/t/android-back-button-code/4545/3 "2014-05-21T02:25:10Z")

</div>

> [@mhartington](#):
>
> .controller(‘MyCtrl’, function($scope, $ionicPlatform) {  
> $ionicPlatform.onHardwareBackButton( function(){  
> // Your function here  
> })

thanks ill try it out and let you know

---

<div class="post-metadata">

**Author:** ![Jana](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@Jana](https://forum.ionicframework.com/u/Jana)\
**Post date:** [May 22, 2014, 8:18am UTC](https://forum.ionicframework.com/t/android-back-button-code/4545/4 "2014-05-22T08:18:48Z")

</div>

no luck my friend ! I tried it . Still it works similar to browser history.

---

<div class="post-metadata">

**Author:** ![Jana](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@Jana](https://forum.ionicframework.com/u/Jana)\
**Post date:** [May 22, 2014, 9:41am UTC](https://forum.ionicframework.com/t/android-back-button-code/4545/5 "2014-05-22T09:41:37Z")

</div>

Hi Mike , it worked at last . Thanks for the input guys .

I wanted to check this out in windowsphone , if it works hurray!!!

Cheers Guys ! loving Ionic
