Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

SecuredPreference returns null in application class. #82

Open
tarunattri opened this issue Apr 30, 2018 · 2 comments
Open

SecuredPreference returns null in application class. #82

tarunattri opened this issue Apr 30, 2018 · 2 comments

Comments

@tarunattri
Copy link

In my use case I have to check for a String stored in SecuredPreference in Application class onCreate() method.

For that I try to get the String from SecuredPreference in onCreate of MyApplication class. but here most of the times, SecuredPreference returns null values.

If i add same code in my activity, it returns non null value.

Looks like SecuredPreference is taking time to intialize. Any hints on why this is happening. Let me know in case additional info is needed for this.

@holysheep
Copy link

holysheep commented May 17, 2018

Did you use common preference filename for your shared preferences?
Which context passed in SecurePreferences constructor?

Problem somehow can be caused by decryption itself, try to breakpoint encryptedValue in SecurePreferences to check it's presence:

  @Override
    public String getString(String key, String defaultValue) {
        final String encryptedValue = sharedPreferences.getString(
                SecurePreferences.hashPrefKey(key), null);

        String decryptedValue = decrypt(encryptedValue);
        if (encryptedValue != null && decryptedValue != null) {
            return decryptedValue;
        } else {
            return defaultValue;
        }
    }

@tarunattri
Copy link
Author

PFB my answers inline :
Did you use common preference filename for your shared preferences? : Yes I used common preference File name.
Which context passed in SecurePreferences constructor? IN Application class's onCreate(), context of application is passed. In case of LauncherActivity class, context of Launcher Activity is passed.

Problem somehow can be caused by decryption itself : If it was problem caused by decryption, than it would exist everywhere, but in my case only in Application class's onCreate it is returning null.

I hope it clears the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants