Skip to content

Commit 9919c39

Browse files
committed
Moved appContext null check before thread start
* This is more efficient as we are not creating a thread before it is possible write * This eliminates entries points into Thread.start to help debug issue #917
1 parent f69f084 commit 9919c39

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalPrefs.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ public static class WritePrefHandlerThread extends HandlerThread {
133133
}
134134

135135
synchronized void startDelayedWrite() {
136+
// A Context is required to write,
137+
// if not available now later OneSignal.setContext will call this again.
138+
if (OneSignal.appContext == null)
139+
return;
140+
136141
if (mHandler == null) {
137142
startThread();
138143
mHandler = new Handler(getLooper());
@@ -194,10 +199,6 @@ public void run() {
194199
}
195200

196201
private void flushBufferToDisk() {
197-
// A flush will be triggered later once a context is set via OneSignal.setAppContext(...)
198-
if (OneSignal.appContext == null)
199-
return;
200-
201202
for (String pref : prefsToApply.keySet()) {
202203
SharedPreferences prefsToWrite = getSharedPrefsByName(pref);
203204
SharedPreferences.Editor editor = prefsToWrite.edit();

0 commit comments

Comments
 (0)