diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java index a247a4877..ea13096ca 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java @@ -38,11 +38,8 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity; import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter; -import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; -import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager; -import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -338,19 +335,6 @@ public class ControlCenter extends GBActivity { for (GBDevice device : deviceList) { if (device.isConnected() || device.isConnecting()) { connectedDevice = device; - if (device.isInitialized()) { - try (DBHandler dbHandler = GBApplication.acquireDB()) { - DaoSession session = dbHandler.getDaoSession(); - - if (DBHelper.findDevice(device, session) == null) { - DBHelper.getDevice(device, session); // implicitly creates it :P - Intent startIntent = new Intent(ControlCenter.this, OnboardingActivity.class); - startIntent.putExtra(GBDevice.EXTRA_DEVICE, device); - startActivity(startIntent); - } - } catch (Exception _ignore) { - } - } break; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index c604359f0..1d225cec6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -25,6 +25,10 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.activities.OnboardingActivity; +import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; +import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; +import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver; import nodomain.freeyourgadget.gadgetbridge.externalevents.K9Receiver; @@ -145,6 +149,23 @@ public class DeviceCommunicationService extends Service implements SharedPrefere boolean enableReceivers = mDeviceSupport != null && (mDeviceSupport.useAutoConnect() || mGBDevice.isInitialized()); setReceiversEnableState(enableReceivers); GB.updateNotification(mGBDevice.getName() + " " + mGBDevice.getStateString(), mGBDevice.isInitialized(), context); + + if (device.isInitialized()) { + try (DBHandler dbHandler = GBApplication.acquireDB()) { + DaoSession session = dbHandler.getDaoSession(); + if (DBHelper.findDevice(device, session) == null) { + DBHelper dbHelper = new DBHelper(context); + if (dbHelper.getOldActivityDatabaseHandler() != null) { + DBHelper.getDevice(device, session); // implicitly creates it :P + Intent startIntent = new Intent(context, OnboardingActivity.class); + startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startIntent.putExtra(GBDevice.EXTRA_DEVICE, device); + startActivity(startIntent); + } + } + } catch (Exception _ignore) { + } + } } else { LOG.error("Got ACTION_DEVICE_CHANGED from unexpected device: " + mGBDevice); }