Shared Preferences does not work

Asked

Viewed 13 times

-1

I’m making an application where in the database makes a summation, along with an innerjoin After running this selection, I want it to save the values in a Shared preferences. But always when I try to rescue the values it gives me the message that there is no data saved, I hope you can help me.

====================

Java - Recover

=====================

private void fillMonthValue(){
        SharedPreferences prefs = getSharedPreferences("userInfo",
                Context.MODE_PRIVATE);
        int idUser = prefs.getInt("idUser", 0);
        OperationsDao.getMonthValue(getApplicationContext(),idUser);

        SharedPreferences prefers = getSharedPreferences("bkCardSelected",
                Context.MODE_PRIVATE);
        String testandoo = prefers.getString("Month1", "não há");
        Toast toast = Toast.makeText(getApplicationContext(),
                testandoo, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
        toast.show();
}

======================

Java - Dao

======================


public static void getMonthValue(Context ctx,int idUser){
        SharedPreferences prefs = ctx.getSharedPreferences("bkCardSelected",
                Context.MODE_PRIVATE);
        int idBank = prefs.getInt("idBank", 0);
        try{
            for (int i = 1;i<12;i++){

                PreparedStatement pst =
                        Connexion.join(ctx).prepareStatement("select SUM(valueEarn) from earnAccount " +
                                "inner join bankAccount on bankAccount.idBankAccount = bankAccount.selectedBank " +
                                "where Month(dateEarnCreate) = "+i+" and selectedBank = 1 and earnAccount.idCli ="+idUser +"and earnAccount.idBankAccount="+idBank+
                                "group by selectedBank");
                ResultSet res = pst.executeQuery();
                String result = "Month"+i;
                while (res.next()) {
                    @SuppressLint("CommitPrefEdits")
                    SharedPreferences.Editor edit = prefs.edit();
                    edit.putString(result, res.getString(1));
                    edit.apply();
                }
                i = i+1;
            }
        }catch(SQLException e){
            Toast toast= Toast.makeText(ctx.getApplicationContext(),
                    "erro" + e.getMessage(), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 0);
            toast.show();
        }
    }

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.