1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to return to Fragment from Activity on Back Press

Discussion in 'Android Development' started by Marinus Snyman, May 21, 2021.

  1. Marinus Snyman

    Thread Starter


    In Android Studio I created a HomeFragment from MainActivity, then a new Activity is started when Bluetooth Data arrives. When I press the Back button while in the new Activity, the app closes. I want the App to go back to the HomeFragment.

    I tried the following in the new Activity: But the App still closes:

    Code (Text):
    1. @Override
    2.     public void onBackPressed() {
    3.         finish();
    4.     }
    The FLow of code is in the attached image:

    Thanx for the help

    Attached Files:

    1. Download the Forums for Android™ app!


  2. Unforgiven

    Unforgiven ...eschew obfuscation...

    I moved this to the development forum to get some better eyes on it. Good luck :)
    codesplice and Marinus Snyman like this.
  3. Marinus Snyman

    Thread Starter

    So where will I get feedback then?
  4. Unforgiven

    Unforgiven ...eschew obfuscation...

  5. Marinus Snyman

    Thread Starter

    Hi Unforgiven. I got my answer on another forum. I had to remove FLAG_ACTIVITY_CLEAR_TASK when I started the Activity. :)
    Unforgiven likes this.

Share This Page