# backPressed() not working on second activity

**URL:** https://discourse.processing.org/t/backpressed-not-working-on-second-activity/17398
**Category:** Processing for Android
**Created:** [January 28, 2020, 7:04pm UTC](https://discourse.processing.org/t/backpressed-not-working-on-second-activity/17398 "2020-01-28T19:04:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pallav12](https://avatars.discourse-cdn.com/v4/letter/p/34f0e0/32.png) [@pallav12](https://discourse.processing.org/u/pallav12)
#### Post date: [January 28, 2020, 7:04pm UTC](https://discourse.processing.org/t/backpressed-not-working-on-second-activity/17398/1 "2020-01-28T19:04:05Z")

</div>

I tried opening new Activity in setup of Sketch.java using startActivity(intent) but on second activity I noticed back button not working ie not leading to first activity… Is this a issue in core library? I am using processing for android through android studio

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [January 29, 2020, 9:00am UTC](https://discourse.processing.org/t/backpressed-not-working-on-second-activity/17398/2 "2020-01-29T09:00:43Z")

</div>

@pallav12 ===  
can you put some code snippet?  
when are you creating the second activity?  
when you hit the back button what is happening?- Do you stay in the 2° activity?

---

<div class="post-metadata">

### Author: ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)
#### Post date: [January 29, 2020, 9:42am UTC](https://discourse.processing.org/t/backpressed-not-working-on-second-activity/17398/3 "2020-01-29T09:42:22Z")

</div>

Maybe this helps you

> [@Android Studio + Processing](https://discourse.processing.org/t/android-studio-processing/12954):
>
> Hi, people wave!! After a while trying it, finally I made it. I’m capable to launch Sketches from P3 (Processing 3) in Android Studio and pass them some values. I don’t have many technical knowledge, but no one told me how to do it, so I want to share this example to people who have the same goal, to save time. Here is the code in AS: MainActivity: package processing.test.mixing1; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.suppo…

```auto
    @Override
    public void onBackPressed() {
        Intent gBack = new Intent(getActivity(),MainActivity.class);
        startActivity(gBack);
    }

```

---

<div class="post-metadata">

### Author: ![pallav12](https://avatars.discourse-cdn.com/v4/letter/p/34f0e0/32.png) [@pallav12](https://discourse.processing.org/u/pallav12)
#### Post date: [January 29, 2020, 9:48am UTC](https://discourse.processing.org/t/backpressed-not-working-on-second-activity/17398/4 "2020-01-29T09:48:23Z")

</div>

```auto
public class Sketch extends PApplet {

  PImage leaf;

  public void settings() {
    fullScreen();
  }

  public void setup() {
    leaf = loadImage("leaf.png");
    imageMode(CENTER);
    Intent intent=new Intent(getActivity(), Main2Activity.class);
    startActivity(intent);

  }

  public void draw() {
    background(9);
    image(leaf, mouseX, mouseY);
    Button button=new Button(getContext());

  }

}

```

this is how i opened new activity  
Now back press isn’t doing anything  
but when I changed PApplet code

```auto
synchronized public void onBackPressed() {
    requestedBackPress = true;
  }

```

to

```auto
synchronized public void onBackPressed() {
    requestedBackPress = true;
    handleBackPressed();
  }

```

it worked perfectly as expected.  
Is this a bug?
