iamMehedi / Secured-Preference-Store

A cryptography library and a SharedPreferences wrapper for Android that encrypts the content with 256 bit AES encryption. The Encryption key is securely stored in device's KeyStore.
562 stars 97 forks source link

llegalStateException: Must call init() before using the store #40

Open gerostam opened 5 years ago

gerostam commented 5 years ago

Hello,

I am using the library and works fine in all the devices that I tested so far. The problem is that I receive crashes in production for some older devices (i.e. Samsung Note 3 with Android 5):

llegalStateException: Must call init() before using the store in SecuredPreferenceStore.setRecoveryHandler

, but I call init as it is stated in the documentation (cannot replicate it on devices that I have available).

Please provide a fix and let me know!

iamMehedi commented 5 years ago

Most probably a memory issues, will check!

lucianommoura commented 5 years ago

Most probably a memory issues, will check!

I dont think so. I have the same error at my application and all users have a lot of memory free.

edgar-zigis commented 5 years ago

We have a big user base, so I can confirm, that 95% of the crashes occur on Android 5 and earlier and the other 5% are occuring on Android 6.0-6.0.1.

gerostam commented 5 years ago

What I did to solve this (this is not the best solution as the library should not crash) is:

SecuredPreferenceStore securedPreferenceStore; try { securedPreferenceStore = SecuredPreferenceStore.getSharedInstance(); } catch (Exception e) { LOGGER.error(e.toString(), e); generateSecuredSharedPreferences(context); securedPreferenceStore = SecuredPreferenceStore.getSharedInstance(); }

, when I try to use the the SecuredPreferenceStore Singleton