Skip to content

Commit e652adc

Browse files
Android background fix (#349)
1 parent 9bf0df1 commit e652adc

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -551,47 +551,46 @@ static synchronized void start(final Context context, final String userId,
551551
}
552552
return;
553553
}
554+
// Reduce latency by running the rest of the start call in a background thread.
555+
Util.executeAsyncTask(true, new AsyncTask<Void, Void, Void>() {
556+
@Override
557+
protected Void doInBackground(Void... params) {
558+
initializedMessageTemplates = true;
559+
MessageTemplates.register(Leanplum.getContext());
554560

555-
initializedMessageTemplates = true;
556-
MessageTemplates.register(Leanplum.getContext());
557-
558-
LeanplumInternal.setStartedInBackground(actuallyInBackground);
559-
560-
final Map<String, ?> validAttributes = LeanplumInternal.validateAttributes(attributes,
561-
"userAttributes", true);
562-
LeanplumInternal.setCalledStart(true);
563-
564-
if (validAttributes != null) {
565-
LeanplumInternal.getUserAttributeChanges().add(validAttributes);
566-
}
561+
LeanplumInternal.setStartedInBackground(actuallyInBackground);
567562

568-
RequestOld.loadToken();
569-
VarCache.setSilent(true);
570-
VarCache.loadDiffs();
571-
VarCache.setSilent(false);
572-
LeanplumInbox.getInstance().load();
563+
final Map<String, ?> validAttributes = LeanplumInternal.validateAttributes(attributes,
564+
"userAttributes", true);
565+
LeanplumInternal.setCalledStart(true);
573566

574-
// Setup class members.
575-
VarCache.onUpdate(new CacheUpdateBlock() {
576-
@Override
577-
public void updateCache() {
578-
triggerVariablesChanged();
579-
if (RequestOld.numPendingDownloads() == 0) {
580-
triggerVariablesChangedAndNoDownloadsPending();
567+
if (validAttributes != null) {
568+
LeanplumInternal.getUserAttributeChanges().add(validAttributes);
581569
}
582-
}
583-
});
584-
RequestOld.onNoPendingDownloads(new RequestOld.NoPendingDownloadsCallback() {
585-
@Override
586-
public void noPendingDownloads() {
587-
triggerVariablesChangedAndNoDownloadsPending();
588-
}
589-
});
590570

591-
// Reduce latency by running the rest of the start call in a background thread.
592-
Util.executeAsyncTask(true, new AsyncTask<Void, Void, Void>() {
593-
@Override
594-
protected Void doInBackground(Void... params) {
571+
RequestOld.loadToken();
572+
VarCache.setSilent(true);
573+
VarCache.loadDiffs();
574+
VarCache.setSilent(false);
575+
LeanplumInbox.getInstance().load();
576+
577+
// Setup class members.
578+
VarCache.onUpdate(new CacheUpdateBlock() {
579+
@Override
580+
public void updateCache() {
581+
triggerVariablesChanged();
582+
if (RequestOld.numPendingDownloads() == 0) {
583+
triggerVariablesChangedAndNoDownloadsPending();
584+
}
585+
}
586+
});
587+
RequestOld.onNoPendingDownloads(new RequestOld.NoPendingDownloadsCallback() {
588+
@Override
589+
public void noPendingDownloads() {
590+
triggerVariablesChangedAndNoDownloadsPending();
591+
}
592+
});
593+
595594
try {
596595
startHelper(userId, validAttributes, actuallyInBackground);
597596
} catch (Throwable t) {

0 commit comments

Comments
 (0)