Search code examples
androidandroid-intentandroid-event

Can we detect if android app is updated from google play on introduction of a new version?


I have a app on play store and i want to provide app update through the play store.

Also, on updation of the app i want to perform some task. So, how can i perform a task on updation of my app from the play store.

I thought of maintaining current version and cross check it every time the app is fired, is there any other efficient way such as any intent fired on app updation that can be handled on the device itself.


Solution

  • You can save your current version code in shared preferences and on upgrade, cross check the new version with the previously stored one.

    if (savedVersionCode < currentVersionCode) {
        .
        .
        //PERFORM CERTAIN TASKS...
        .
        .
    }
    

    You can do this in your application's onCreate() or simply in you launcher activity's onCreate() if you have only one entry point.