ban-geoengineering ban-geoengineering - 1 month ago 6
Android Question

How to go back from native Android settings screen?

In my app, the user goes from

ActivityA
to
ActivityB
.
ActivityB
displays an NFC Settings button. When the user clicks that button, this code is executed to show the native NFC Settings screen:

Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
intent = new Intent(android.provider.Settings.ACTION_NFC_SETTINGS);
}
else {
intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
}
startActivity(intent);
showToast("Press Back button when done");


The problem I'm having is that when the user is viewing the native NFC Settings screen and presses the device's back button, they are taken all the way back to
ActivityA
.

Is there a clean way to solve this problem so that the user goes back to
ActivityB
, as required/expected?

Answer

Seems like the application process was killed in background, although in this case Android would have restored the back stack... Make sure you are not calling finish() after startActivity() in ActivityB or try using startActivityForResult() instead of startActivity(). This is not a panacea though!