How can I execute something just once per application start?

前端 未结 10 1400
感情败类
感情败类 2020-11-28 06:45

I\'d like to implement an update checker in an application, and I obviously only need this to show up once when you start the application. If I do the call in the onCr

10条回答
  •  粉色の甜心
    2020-11-28 07:18

    I do this the same way as described in the other answer. I just have a global variable in the first activity which matches the release number from the manifest. I increment it for every upgrade and when the check sees a higher number, it executes the one-time code.

    If successful, it writes the new number to shared preferences so it wont do it again until the next upgrade.

    Make sure you assign the default to -1 when you retrieve the version from shared preferences so that you error on the side of running the code again as opposed to not running it and not having your app update correctly.

提交回复
热议问题