Domanda

So this is the first time I am going to send an update for my app and I don't know about what actully happens when an app is updated via google-play,

Here are some questions those I couldn't get answer of :

  • What is actually updated and how this process works i.e. methods or callbacks when update is done ?

  • What happens to the shared-preferences file, the name values pairs change/reset ?

Let's say I want to download some file from a server , when the app is updated via google play and do some db operations with that file in the background. How can I approach this in the right way.

--Edit--

To make it more clear I want to automatically do some processing when the app is updated by user and he doesn't bother to open the app and to achieve this I am looking for a trigger that is provided by google play to my app by any intent [implicit or explicit].

È stato utile?

Soluzione

You need to implement a Broadcast Receiver that gets notified when the Paackage is beeing replaced:
In your Manifest include:

<receiver android:name="my.package.MyReceiver">
  <intent-filter>
  <action android:name="android.intent.action.PACKAGE_REPLACED"/>
    <data android:scheme="package" /> 
  </intent-filter>
</receiver>

The class MyReceiver needs to extend android.content.BroadcastReceiver

To Answer your second question: The SharedPreferences aren't affected by an update through Google Play, as aren't the files in your App's data-Folder.

Altri suggerimenti

One way of checking if a new version has been installed is to use shared preferences. When the app is opened, you can check if an entry for that version is present. If it's not, a new version has been installed. After your processing is done, you can save the current version number in shared preferences.

As for your second question, shared preferences are not lost or reset by the update process. They stay as they were.

You may be out of luck here as there is no clean way to do this with an already installed app. If you have in-app billing (and this is speculation) and Google's in-app billing system has a dynamic dashboard or API to register users, then, you can say setup a new unique key of some sort and track it through this in-app billing like system. This may not be possible though.

The second thing you can do is to look up users in your server database and create this file you mention for all users and hold them in server cache (for fast access). Then in your app on first launch of this new version you can quickly get this file to user. This seems to be a good safe solution.

Good Luck, this is an interesting problem and I will be looking forward to hearing how you will solve this.

Just remembered, you can also look into push notifications and pushing this data to users. But, this assumes your app has this.

@prateek User need to start the App manually from Android 3.1 to apply the Broadcast Receiver Solution. I do not think you have any option...Sorry Mate...A small advice is that, try to put a push notification handler when you really want to do something with user interaction or a broadcast receiver to trigger frequent operations without User Interaction...Cheers!

You can approach in this way

in the first time user install and start the application, you should store the current version as last_vertion_of_app in the shared preferences. then use a alarm Manager +broadcast receiver+service to check the manifest app version with shared preference stored version if both are different(not equal) that means some update happen. then you can do the thing what you want to happen if updated=true in the save service even without application starts.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top