Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immediate update does not restart the app automatically after installing. #82

Closed
AkaankshK opened this issue Oct 18, 2022 · 3 comments
Closed

Comments

@AkaankshK
Copy link

AkaankshK commented Oct 18, 2022

Hi,
When we perform a flexible update, the app restarts automatically after installing the update, but in the case of immediate update it installs the update but does not restart the app automatically.

Heres my code:

  void handleBootStart() async {
    await ServicesManager.initAttributionService();
    User? user = FirebaseAuth.instance.currentUser;
    AppUpdateModel updateData = await AppUpdateService().isAppUpdateAvailable();
    if (updateData.isAppUpdateAvailable &&
        !Get.find<AppSession>().state.canSkipAppUpdate) {
      setSplashAnimationAsComplete();
      if (Platform.isAndroid && updateData.useInAppUpdate) {
        //In app update code
        final _updateDataFromPlayStore = await InAppUpdate.checkForUpdate();
        if (updateData.forceUpdate &&
            _updateDataFromPlayStore.immediateUpdateAllowed) {
          InAppUpdate.performImmediateUpdate().catchError((e) {
            App.showSnackBar(title: e.toString());
          });
        } else if (updateData.isAppUpdateAvailable &&
            _updateDataFromPlayStore.flexibleUpdateAllowed) {
          emit(state.copyWith(
              isSplashAnimationOver: false, isFlexibleUpdateLoading: true));
          final _result = await InAppUpdate.startFlexibleUpdate();
          if (_result == AppUpdateResult.userDeniedUpdate) {
            emit(state.copyWith(
                isSplashAnimationOver: true, isFlexibleUpdateLoading: false));
            _handleNavigationDestination(user);
          } else if (_result == AppUpdateResult.success) {
            await InAppUpdate.completeFlexibleUpdate();
          }
        } else {
          _handleNavigationDestination(user);
        }
      } else {
        Sailor.replaceStackWithWidget(AppUpdateScreen(
          updateData: updateData,
          onSkip: () => _handleNavigationDestination(user),
        ));
      }
    } else {
      _handleNavigationDestination(user);
    }
  }

@jonasbark

@jonasbark
Copy link
Owner

If the update is applied in Android OS then there's no way that the app stays alive. Probably you're not awaiting the performImmediateUpdate future or an error happens in between.

@AkaankshK
Copy link
Author

@jonasbark

this was my production previous code, I was awaiting the future, but it did not work, so i tried the example, that did not help either :/

if (updateData.forceUpdate && _updateDataFromPlayStore.immediateUpdateAllowed) {
          final _result = await InAppUpdate.performImmediateUpdate();
          if (_result == AppUpdateResult.userDeniedUpdate) {
            Sailor.replaceStackWithWidget(AppUpdateScreen(
              updateData: updateData,
              onSkip: () => _handleNavigationDestination(user),
            ));
          }
          if (_result == AppUpdateResult.success) {
            _handleNavigationDestination(user);
          }
        }

@AkaankshK
Copy link
Author

@jonasbark and everyone else who is facing this issue,

I read in a google issue tracker that in android 10 and above, this restart is not working, so i changed the the launch mode in android manifest file and it started working.

android:launchMode="singleTask"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants