bitstadium / HockeySDK-Android

HockeyApp was retired and the SDKs are deprecated. Please use App Center instead.
https://github.com/microsoft/appcenter-sdk-android
Other
279 stars 131 forks source link

UpdateManager not working #150

Closed PatrickMA closed 8 years ago

PatrickMA commented 8 years ago

I've a strange problem which I want to share with you:

I'm checking in the LoginActivity of my application for updates. But sometimes no update dialog is shown, even if the new version in HockeyApp is a mandatory update. So I decided to implement a custom UpdateManagerListener which loads the LoginFragment if no update is available, otherwise the UpdateDialog will be shown anyway.

In the onCreate()-method of my Activity, I do this:

UpdateManager.register(this, Constants.HockeyApp.APP_ID, new UpdateManagerListener() {
  @Override
  public void onNoUpdateAvailable() {
    super.onNoUpdateAvailable();

    // no update is available ->  load login screen
    setFragment(R.id.container_login, new LoginFragment());
  }

  @Override
  public void onUpdateAvailable(JSONArray data, String url) {
    super.onUpdateAvailable(data, url);
  }
}, true);

But on some phones the dialog will be shown, and on other not. Neither onNoUpdateAvailable() nor onUpdateAvailable() seems to be called, which is very strange.

matthiaswenz commented 8 years ago

Hi @PatrickMA, thanks for reporting this. I will look into this. Can you share any more information to isolate the issue? Do you see a particular pattern around device OEMs, OS versions, network connectivity, or in regards to the frequency of this occurring? Which SDK version are you referring to? If you need to share private information, feel free to open a support request and I will take care of this.

Best, Mat

PatrickMA commented 8 years ago

Hey @ranterle!

SDK Version ... 3.7.0, but also tried with 4.0.0-beta.1 Works on ... Android Emulator (6.0.1 with Google APIs), Xperia Z3 D6603 (Android 5.1.1) Does not work on ...Nexus 5 (Android 6.0.1), OnePlus One (Android 5.1.1), OnePlus Two (Android 5.1.1 and 6.0.1, but works on another OnePlus Two with Android 5.1.1)

I have not tried it on other phones yet and I cannot say something about the network connectivity and the frequency of this problem.

I hope this information will help you find the problem. Until then ... thank you!

PatrickMA commented 8 years ago

Edit: I cleaned up the code a bit:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    checkForUpdates();
    setTitle("Login");
}

private void checkForUpdates() {
    if (!BuildConfig.DEBUG) {
        UpdateManager.register(this, Constants.HockeyApp.APP_ID, new UpdateManagerListener() {
            @Override
            public void onNoUpdateAvailable() {
                setFragment(R.id.container_login, new LoginFragment());
            }
        }, true);
    } else {
        setFragment(R.id.container_login, new LoginFragment());
    }
}

The setFragment() method looks like this:

protected void setFragment(int fragmentResourceId, Fragment fragment) {
    getSupportFragmentManager().beginTransaction()
            .replace(fragmentResourceId, fragment)
            .commit();
}
matthiaswenz commented 8 years ago

The only reason I can think of right now is, that those devices maybe return something off in installedFromMarket. The problem is, that debugging the issue will change the results you will get (if you install via ADB it will yield different results than if you install through HockeyApp in the relevant call). To narrow it down, can you override canUpdateInMarket() to return true in your custom UpdateManagerListener and see if this resolves the issue?

If the issue persists, the only other option is for you to provide a sample project and instructions to reproduce the issue.

Best, Mat

PatrickMA commented 8 years ago

Thank you for the answer @ranterle ! I tried it and published it to a tester (OnePlus One - Android 5.1.1). After updating the application it works perfectly, but a few hours later it didn't start anymore.

One more question: Why should I override canUpdateInMarket() and return true? If the user could update in the Google Play Store, why should the update dialog pop up? What does the method at all? The javadoc is not clear enough for me.

I could try to make an sample project and deploy that via HockeyApp to some testers and look if the problem occurs again. Then I will push the project to a GitHub Repository and post the link here.

ElektrojungeAtWork commented 8 years ago

Hi @PatrickMA,

Matthias (@ranterle) is now on vacation, so I'll take over for him.

So you're saying that the update worked but after a few hours the app didn't start all anymore?

About your questions regarding canUpdateInMarket(): AFAIK Matthias asked you to override it because we had issues in the past where certain devices reported weird stuff so HockeySDK "thought" the app is in a market environment and didn't show the update dialog. (FYI, here's the code for the updates) Sorry for the very brief javadoc. This was a feature request so users could deploy updates to apps that are in the market via hockeyapp, which can be quicker, etc. etc.

About the sample project. That would be awesome. I tried this with a sample project here myself without any success, I can't repro the issue, but then I don't have the One Two.

Please get in touch so we can nail the issue down and solve this. =)

PatrickMA commented 8 years ago

Hey @TroubleMakerBen,

Thank you! I've now invited more testers for the version of my application with the overridden canUpdateInMarket() and it seems that the problem does not occur as often as before. It seems the problem reported yesterday on the OnePlus One only occured once and a few hours later the application worked as normal as it should.

I will invite more testers to look if the problem still exists and come back again later with the results.

matthiaswenz commented 8 years ago

Hi @PatrickMA do you have an update on this or does it still occur infrequently?

matthiaswenz commented 8 years ago

Closing this until it can be reproduced reliably.