• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to return to Fragment from Activity on Back Press

Hello

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:
@Override
    public void onBackPressed() {
        finish();
    }

The FLow of code is in the attached image:

Thanx for the help
 

Attachments

  • Back Button Android (1).jpeg
    Back Button Android (1).jpeg
    88.3 KB · Views: 217

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones