@@ -173,7 +173,7 @@ public OptimizelyClient initialize(@NonNull Context context, @NonNull String dat
173
173
* @param downloadToCache to check if datafile should get updated in cache after initialization.
174
174
* @return an {@link OptimizelyClient} instance
175
175
*/
176
- protected OptimizelyClient initialize (@ NonNull Context context ,@ Nullable String datafile ,boolean downloadToCache ) {
176
+ protected OptimizelyClient initialize (@ NonNull Context context , @ Nullable String datafile , boolean downloadToCache ) {
177
177
if (!isAndroidVersionSupported ()) {
178
178
return optimizelyClient ;
179
179
}
@@ -277,31 +277,44 @@ public void run() {
277
277
* @return datafile
278
278
*/
279
279
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 ;
295
295
}
296
+
296
297
/**
297
298
* Starts Optimizely asynchronously
298
299
* <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}.
305
318
* @param context any type of context instance
306
319
* @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)}
307
320
* @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
313
326
return ;
314
327
}
315
328
setOptimizelyStartListener (optimizelyStartListener );
316
- datafileHandler .downloadDatafile (context , datafileConfig ,getDatafileLoadedListener (context ,datafileRes ));
329
+ datafileHandler .downloadDatafile (context , datafileConfig , getDatafileLoadedListener (context ,datafileRes ));
317
330
}
318
331
319
332
DatafileLoadedListener getDatafileLoadedListener (final Context context , @ RawRes final Integer datafileRes ) {
@@ -614,6 +627,9 @@ public static class Builder {
614
627
@ Nullable private DatafileConfig datafileConfig = null ;
615
628
616
629
@ Deprecated
630
+ /**
631
+ * @deprecated use {@link #Builder()} instead and pass in an SDK Key with {@link #withSDKKey(String)}
632
+ */
617
633
Builder (@ Nullable String projectId ) {
618
634
this .projectId = projectId ;
619
635
}
0 commit comments