Skip to content

Instantly share code, notes, and snippets.

@bengongon97
Created July 20, 2020 10:44
Show Gist options
  • Save bengongon97/b1d9af9a0e066c20ee9a5f1fb7b7c867 to your computer and use it in GitHub Desktop.
Save bengongon97/b1d9af9a0e066c20ee9a5f1fb7b7c867 to your computer and use it in GitHub Desktop.
Overriding onBackPressed for AccountKit functionality
@Override
public void onBackPressed() {
if(doubleBackToExitPressedOnce){
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);
}
else{
Toast.makeText(this, "Please click again BACK to exit", Toast.LENGTH_SHORT).show();
doubleBackToExitPressedOnce = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment