Reputation: 55
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
@Override
public void onBackPressed() {
finish();
}
Here is the flow of my code for the sequence mentioned.
Upvotes: 1
Views: 73
Reputation: 95578
When you launch Activity_ListViewInp
you have added FLAG_ACTIVITY_NEW_TASK
and FLAG_ACTIVITY_CLEAR_TASK
. This will remove all existing activities from the task and start a new instance of Activity_ListViewInp
. When you then press BACK, the app exits because there are no other activities in the task.
Remove FLAG_ACTIVITY_CLEAR_TASK
Upvotes: 1