Close firebase session when closing activity-Android

0

I want to create a kind of login, that by checking a checkbox, I can remember the session or end the session when closing the application if the checkbox is disabled, for that I use sharedpreferences to save the status of the checkbox, but when executing it in the onDestroy method of the activity, the code is not executed, the code of my onDestroy method is this:

    @Override
     public void onDestroy() {
            super.onDestroy();
            Crouton.cancelAllCroutons();
            SharedPreferences loginbdd = getSharedPreferences("login", Context.MODE_PRIVATE);
            String salto=loginbdd.getString("inicio","");
            if(salto.equals("cerrar")){
                Log.d("ONSTOP","EJECUTADO");
                FirebaseAuth.getInstance().signOut();
            }
        }

verifique el valor de la preferencia y esta se guarda perfectamente, pero la sesion, sigue sin cerrarse, cabe mencionar que lo probe en el metodo onStop y tampoco funciono

I hope you can help me, in advance, thank you very much

edit: onBackPressed method that you mention in a response

@Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else if (snackbar != null && snackbar.isShown()) {
            snackbar.dismiss();
        } else {
            new AlertDialog.Builder(MainActivity.this)
                    .setIcon(R.drawable.cerrar).setTitle("Cerrar Aplicación").setMessage("Deseas cerrar CicloMapp?")
                    .setCancelable(true).setPositiveButton("Si", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SharedPreferences loginbdd = getSharedPreferences("login", Context.MODE_PRIVATE);
                    String salto = loginbdd.getString("inicio", "");
                    if(salto.equals("cerrar")){
                        Log.d("OnDestroy","EJECUTADO");
                        SharedPreferences.Editor editor = loginbdd.edit();
                        editor.remove("inicio");
                        editor.commit();
                        FirebaseAuth.getInstance().signOut();
                        System.exit(0);
                    }
                }

            })
                    .setNegativeButton("No", null).show();
        }
    }
    
asked by zhet 22.03.2017 в 04:40
source

1 answer

0

zhet, try running the super.onDestroy () at the end:

@Override public void onDestroy() {
    Crouton.cancelAllCroutons();
    SharedPreferences loginbdd = getSharedPreferences("login", Context.MODE_PRIVATE);
    String salto=loginbdd.getString("inicio","");
    if(salto.equals("cerrar")){
        Log.d("ONSTOP","EJECUTADO");
        FirebaseAuth.getInstance().signOut();
    }
    super.onDestroy();
}
    
answered by 22.03.2017 / 05:14
source