backPressed() not working on second activity

I tried opening new Activity in setup of 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

@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?

Maybe this helps you

    public void onBackPressed() {
        Intent gBack = new Intent(getActivity(),MainActivity.class);
public class Sketch extends PApplet {

  PImage leaf;

  public void settings() {

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


  public void draw() {
    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

synchronized public void onBackPressed() {
    requestedBackPress = true;


synchronized public void onBackPressed() {
    requestedBackPress = true;

it worked perfectly as expected.
Is this a bug?