diff --git a/lib/src/services/background/callback_dispatcher.background.dart b/lib/src/services/background/callback_dispatcher.background.dart index 94980df..0286c11 100644 --- a/lib/src/services/background/callback_dispatcher.background.dart +++ b/lib/src/services/background/callback_dispatcher.background.dart @@ -49,7 +49,18 @@ void callbackDispatcher() { }); } +bool _isInitialized = false; + Future initBackgroundExecution() async { + if (_isInitialized) { + // Reload the users, as on Android the background isolate can + // stay alive for multiple hours between task executions + final user = await getUser(); + if (user == null) return false; + gUser = user; + return true; + } + SentryWidgetsFlutterBinding.ensureInitialized(); globalApplicationCacheDirectory = (await getApplicationCacheDirectory()).path; globalApplicationSupportDirectory = @@ -65,6 +76,7 @@ Future initBackgroundExecution() async { apiService = ApiService(); globalIsInBackgroundTask = true; + _isInitialized = true; return true; }