MFlisar / GDPRDialog

GDPR fragment dialog implementation
Apache License 2.0
211 stars 53 forks source link

How to check if the library is initialized #62

Closed attanasio94g closed 6 years ago

attanasio94g commented 6 years ago

Hello, how do I know if the library is already initialized?

If is not GDPR.getInstance().getConsentState().getConsent() cause a crash, and I want do to if the library is initialized launch this code, else initialize the library and after launch the code.

I did something like this but maybe there is a better way:

private static boolean GDPR_initialized = false;

 if (!GDPR_initialized){
            GDPR.getInstance().init(activity);
            GDPR_initialized = true;
        }
MFlisar commented 6 years ago

added a function to the master branch for this

https://github.com/MFlisar/GDPRDialog/blob/2235163dc75411244e44539e78babacf130439a0/library/src/main/java/com/michaelflisar/gdprdialog/GDPR.java#L231

In general, you should just initialise GDPR in your application (like here in the demo: https://github.com/MFlisar/GDPRDialog/blob/master/app/src/main/java/com/michaelflisar/gdprdialog/demo/app/App.java), no need to check this if you do it like this...