Exit button on Android

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

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.

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

Cheers
— mnse

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.

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();
}