9

In-app update is available multiple times in my app. User can cancel the update first time while opening the app and choose to trigger in-app Update from another fragment manually.

As per Google documentation, I have created new instances each time to trigger the update but it is only working for the first. Next time, it's causing AppUpdateManager.startUpdateFlowForResult causing IntentSender$SendIntentException

private void init() {
        appUpdateManager = AppUpdateManagerFactory.create(mContext);
        appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

    }

 public void checkAppUpdate() {
            appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
                .....................................
                .....................................
                startAppUpdate(appUpdateInfo);
   
        }

private void startAppUpdate(AppUpdateInfo appUpdateInfo) {
        Log.d(TAG, "startAppUpdate: starting app update");
        appUpdateManager.startUpdateFlowForResult(
                appUpdateInfo,
                appUpdateType,
                mActivityReference,
                mRequestCode);
    }
Asif A. Sohan
  • 202
  • 1
  • 5

2 Answers2

0

According to documentation of startUpdateFlowForResult()

Each AppUpdateInfo instance can be used only in a single call to this method. If you need to call it multiple times - for instance, when retrying to start a flow in case of failure - you need to get a fresh AppUpdateInfo from getAppUpdateInfo().

So, we should renew our appUpdateInfoTask for every calling of startUpdateFlowForResult()

Aliaksei
  • 3,542
  • 1
  • 16
  • 21
-1

As mentioned in the Documentation, there are different flow to trigger Google App Update API from different components in app. We need to trigger correct flow according to our requirements.

startUpdateFlow(AppUpdateInfo appUpdateInfo, Activity activity, AppUpdateOptions options)
Starts the desired update flow asynchronously.

startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, IntentSenderForResultStarter starter, int requestCode)
Starts the desired update flow.

startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, Activity activity, AppUpdateOptions options, int requestCode)
Starts the desired update flow.

startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, int appUpdateType, Activity activity, int requestCode)
Starts the desired update flow.

startUpdateFlowForResult(AppUpdateInfo appUpdateInfo, IntentSenderForResultStarter starter, AppUpdateOptions options, int requestCod
Asif A. Sohan
  • 202
  • 1
  • 5