diff --git a/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java b/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java index 2b235c59..e2331174 100644 --- a/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/activities/SettingsActivity.java @@ -175,10 +175,14 @@ public class SettingsActivity extends SyncthingActivity { mSyncthingService = ((SyncthingActivity) getActivity()).getService(); mSyncthingService.registerOnApiChangeListener(this); - if (mSyncthingService.getApi().isConfigLoaded()) { - mGui = mSyncthingService.getApi().getGui(); - mOptions = mSyncthingService.getApi().getOptions(); - } + // Use callback to make sure getApi() doesn't return null. + mSyncthingService.registerOnWebGuiAvailableListener(() -> { + if (mSyncthingService.getApi().isConfigLoaded()) { + mGui = mSyncthingService.getApi().getGui(); + mOptions = mSyncthingService.getApi().getOptions(); + } + + }); } @Override diff --git a/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java index 52434221..b619989a 100644 --- a/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java +++ b/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java @@ -15,6 +15,7 @@ import android.os.Environment; import android.os.IBinder; import android.os.PowerManager; import android.preference.PreferenceManager; +import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; import android.util.Log; import android.util.Pair; @@ -457,7 +458,7 @@ public class SyncthingService extends Service implements return !new File(getFilesDir(), PUBLIC_KEY_FILE).exists(); } - public RestApi getApi() { + public @Nullable RestApi getApi() { return mApi; }