I have an app with a button. (see image). This preview only occurs if the user has not activated a certain setting. If he presses the button, he arrives in the settings. If he presses back he comes back to the settings. I would now like to intercept this "back".
This back button is directly on the smartphone. How can I intercept this activity? I have found something, unfortunately it does not give me this. Do I have something wrong? or is there something else? Thanks in advance.
public class NfcSettingActivity extends AppCompatActivity {
private Dialog epicDialog;
private Button btn_nfc_navigate_setting;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nfc_setting);
btn_nfc_navigate_setting = findViewById(R.id.btn_nfc_navigate_setting);
btn_nfc_navigate_setting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
System.out.println("back pressed");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
}