Android Learning Series (2) -- download in the notification bar of App auto update

Source: Internet
Author: User

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 -->
4 ></manifest>

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?
1 public class Global {
2     // Version information
3     public static int localVersion = 0;
4     public static int serverVersion = 0;
5 }
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?
01 /**
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.