@@ -173,7 +173,7 @@ public OptimizelyClient initialize(@NonNull Context context, @NonNull String dat
173173 * @param downloadToCache to check if datafile should get updated in cache after initialization.
174174 * @return an {@link OptimizelyClient} instance
175175 */
176- protected OptimizelyClient initialize (@ NonNull Context context ,@ Nullable String datafile ,boolean downloadToCache ) {
176+ protected OptimizelyClient initialize (@ NonNull Context context , @ Nullable String datafile , boolean downloadToCache ) {
177177 if (!isAndroidVersionSupported ()) {
178178 return optimizelyClient ;
179179 }
@@ -277,31 +277,44 @@ public void run() {
277277 * @return datafile
278278 */
279279 public String getDatafile (Context context ,@ RawRes Integer datafileRes ){
280- try {
281- if (isDatafileCached (context )) {
282- return datafileHandler .loadSavedDatafile (context , datafileConfig );
283- } else if (datafileRes !=null ) {
284- return loadRawResource (context , datafileRes );
285- }else {
286- logger .error ("Invalid datafile resource ID." );
287- return null ;
288- }
289- } catch (IOException e ) {
290- logger .error ("Unable to load compiled data file" , e );
291- } catch (NullPointerException e ){
292- logger .error ("Unable to find compiled data file in raw resource" ,e );
293- }
294- return null ;
280+ try {
281+ if (isDatafileCached (context )) {
282+ return datafileHandler .loadSavedDatafile (context , datafileConfig );
283+ } else if (datafileRes !=null ) {
284+ return loadRawResource (context , datafileRes );
285+ }else {
286+ logger .error ("Invalid datafile resource ID." );
287+ return null ;
288+ }
289+ } catch (IOException e ) {
290+ logger .error ("Unable to load compiled data file" , e );
291+ } catch (NullPointerException e ){
292+ logger .error ("Unable to find compiled data file in raw resource" ,e );
293+ }
294+ return null ;
295295 }
296+
296297 /**
297298 * Starts Optimizely asynchronously
298299 * <p>
299- * An {@link OptimizelyClient} instance will be delivered to
300- * {@link OptimizelyStartListener#onStart(OptimizelyClient)}. The callback will only be hit
301- * once. If there is a cached datafile the returned instance will be built from it. The cached
302- * datafile will be updated from network if it is different from the cache. If there is no
303- * cached datafile the returned instance will always be built from the remote datafile.
304- * This method does the same thing except it can be used with a generic {@link Context}.
300+ * See {@link #initialize(Context, Integer, OptimizelyStartListener)}
301+ * @param context any type of context instance
302+ * @param optimizelyStartListener callback that {@link OptimizelyClient} instances are sent to.
303+ * @deprecated Consider using {@link #initialize(Context, Integer, OptimizelyStartListener)}
304+ */
305+ @ TargetApi (Build .VERSION_CODES .ICE_CREAM_SANDWICH )
306+ public void initialize (@ NonNull final Context context , @ NonNull OptimizelyStartListener optimizelyStartListener ) {
307+ initialize (context , null , optimizelyStartListener );
308+ }
309+
310+ /**
311+ * Starts Optimizely asynchronously
312+ * <p>
313+ * * Attempts to fetch the most recent remote datafile and construct an {@link OptimizelyClient}.
314+ * If the datafile has not changed since the SDK last fetched it or if there is an error
315+ * fetching, the SDK will attempt to construct an {@link OptimizelyClient} using a cached datafile.
316+ * If there is no cached datafile, then the SDK will return a dummy, uninitialized {@link OptimizelyClient}.
317+ * Passing in a datafileRes will guarantee the SDK returns an initialized {@link OptimizelyClient}.
305318 * @param context any type of context instance
306319 * @param datafileRes Null is allowed here if user don't want to put datafile in res. Null handling is done in {@link #getDatafile(Context,Integer)}
307320 * @param optimizelyStartListener callback that {@link OptimizelyClient} instances are sent to.
@@ -313,7 +326,7 @@ public void initialize(@NonNull final Context context, @RawRes final Integer dat
313326 return ;
314327 }
315328 setOptimizelyStartListener (optimizelyStartListener );
316- datafileHandler .downloadDatafile (context , datafileConfig ,getDatafileLoadedListener (context ,datafileRes ));
329+ datafileHandler .downloadDatafile (context , datafileConfig , getDatafileLoadedListener (context ,datafileRes ));
317330 }
318331
319332 DatafileLoadedListener getDatafileLoadedListener (final Context context , @ RawRes final Integer datafileRes ) {
@@ -614,6 +627,9 @@ public static class Builder {
614627 @ Nullable private DatafileConfig datafileConfig = null ;
615628
616629 @ Deprecated
630+ /**
631+ * @deprecated use {@link #Builder()} instead and pass in an SDK Key with {@link #withSDKKey(String)}
632+ */
617633 Builder (@ Nullable String projectId ) {
618634 this .projectId = projectId ;
619635 }
0 commit comments