• 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: 246
Back
Top Bottom