# Exit button on Android

**URL:** <https://discourse.processing.org/t/exit-button-on-android/37580>\
**Category:** Processing for Android\
**Created:** [June 16, 2022, 2:16pm UTC](https://discourse.processing.org/t/exit-button-on-android/37580 "2022-06-16T14:16:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![urlxd](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@urlxd](https://discourse.processing.org/u/urlxd)\
**Post date:** [June 16, 2022, 2:16pm UTC](https://discourse.processing.org/t/exit-button-on-android/37580/1 "2022-06-16T14:16:16Z")

</div>

hello, i wanted to ask here i have a code:

```auto
int f = 0;
void setup(){
}

void draw(){
  if(keyPressed){
    f = 255;
    exit();
  }
  fill(f);
  rect(0,0,width, height);
}

```

I wanted that by pressing “back” the program would paint a square and not exit the program. can you suggest how to do it.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 16, 2022, 2:42pm UTC](https://discourse.processing.org/t/exit-button-on-android/37580/2 "2022-06-16T14:42:41Z")

</div>

Hi @urlxd ,

Most probably still not possible within processing android mode. There are several reasons for that but to not digging too deep, here’s a short answer…

[Back button](https://forum.processing.org/one/topic/change-the-functionality-of-the-back-button.html)

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![J\_Silva](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@J\_Silva](https://discourse.processing.org/u/J_Silva)\
**Post date:** [June 26, 2022, 12:41am UTC](https://discourse.processing.org/t/exit-button-on-android/37580/3 "2022-06-26T00:41:44Z")

</div>

Probably too late for this response, but if you want to change the behavior of the back button on an Android device you can try the following code. I include also a code to exit the app by tapping on the middle of the screen. (Just an example.)  
Tested with APDE.

```auto
import android.app.Activity;

boolean switch_to_rect = false;
int f = 0;
Activity act;

void setup(){
  fullScreen();
  act = getActivity();
}

void draw(){
  background(255);
  fill(f);
  if(switch_to_rect) rect(width/2, height/2, 100, 100);
  else ellipse(width/2, height/2, 100, 100);
}

void onBackPressed () {
  switch_to_rect =! switch_to_rect;
}

void mousePressed() {
  if (mouseY < height/2 + 50 && mouseY > height / 2 - 50) act.finish();
}

```
