I have witnessed many upgrades in the blog Park. You also want to notify users of new features by updating your software. Yes.
This article is a must-have knowledge for android Developers. It is specially compiled and summarized for everyone. It is not perfect but useful.
1. design concept. VersionCode is used to define version upgrade parameters.
Android provides two attributes for our defined version:
Html # viewSource "commandName =" viewSource "highlighterId =" highlighter_139799 "> view sourceprint?
1 |
< manifest package = "com.cnblogs.tianxia.subway" |
2 |
android:versionCode = "1" <! -- Integer type, which is not displayed to the user --> |
3 |
android:versionName="1.0" <! -- String type, the system displays the user --> |
Google recommends that we use versionCode auto-increment to indicate version upgrades, whether large changes or small changes, and versionName is used as a display of the Software Version viewed by users. So we chose VersionCode as the parameter for defining version upgrade.
2. project directory
In order to provide practical guidance for real projects or enterprise applications, I simulate an independent project. The project directory settings are reasonable and rigorous, rather than just a demo.
Assume that we use Shanghai Metro as the project and name it "Subway". The project structure is as follows,
3. Compare version initialization with version number.
First, define the variables localVersion and serverVersion in the Global File Global. java to store the local version and server version respectively.
View sourceprint?
3 |
public static int localVersion = 0 ; |
4 |
public static int serverVersion = 0 ; |
This article only focuses on upgrading and updating. To prevent too many other irrelevant code redundancy, I define the initGlobal () method in SubwayApplication. View sourceprint?
02 |
* Initialize global variables |
03 |
* In practice, serverVersion is obtained from the server in this method. It is best to execute it in the activity of the startup screen. |