Hands-on implementation of the weather forecast app (4)-perfection, apk packaging and summary

Perfect and summarize

Change icon and name

Several versions of different resolutions should be provided for the icon icon, and then put them into the mipmap directory of the corresponding resolution.

Name this picture logo.png, put it in all directories starting with mipmap, and then modify the code in Android Manifest xml, as shown below

<application
    android:name="org.litepal.LitePalApplication"
    android:allowBackup="true"
    android:icon="@mipmap/logo"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

You can modify the icon by specifying the icon tag as the logo under mipmap.

It is easier to change the name of the app, just change the app_name in the strings to what you want.

Insert picture description here

<resources>
    <string name="app_name">我的天气</string>
</resources>

At this time, run the program again and you can see that the name and icon have been changed.

Insert picture description here

Generate signed APK and package program

As we all know, the Android system will recognize all APK files as application installation packages, similar to
EXE files on the Window system for installation.
But not all APK files can be successfully installed on the phone. The Android system requires that only signed APK files can be installed, so we also need to sign the generated APK files. Then it seems that when you run the program directly through Android Studio, you can install it without signing it. This is because Android Studio uses a default keystore file to help us sign it automatically.
Insert picture description here

Insert picture description here

Generate official signature

Find the generated signature in the build:

Insert picture description here

There is no official keystore file for the first time, so a new one should be created:

Insert picture description here

After creation, you can remember the password and select the output location directly and click Next.

Insert picture description here

Insert picture description here

to sum up

So far, I have followed the book to complete the entire weather app, experienced the process of the project from creation to implementation, and gained a lot of experience. Here are some conclusions.

  1. First of all, I have a preliminary understanding of the storage of data on the Android mobile terminal. In the previous study, I used it to temporarily store it in the memory. It may be gone next time I run it. The SharedPreferences cache is used in the project, which is a kind of small amount of data. The method of caching, for example, the weather data loaded can be directly retrieved in the next request to avoid the delay of time and traffic when going to the network to apply. The data storage method is the key-value pair storage, and the access is generally Operate through the string key; the other is the use of sqlite that comes with Android, where LiteRal is used, and object-oriented thinking can be used to implement database-related operations, such as defining a Java bean to correspond to a data table, avoiding writing sql Statements are prone to errors.

  2. The second is the compilation of toolkits. Common operations such as network requests can be written as tool classes in the project to be reused. For example, in this project, network requests are encapsulated as HttpUtil classes, which will request weather information, process weather responses, and obtain provinces. The list of cities and counties is encapsulated into a class. In HttpUtilthe sendOkHttpRequest(String address,Callback callback)method can be summarized as routine method, first create a OkHttpClient example, after creating the Request to build incoming address request, after calling the newCall OkhttpClient () method to create a Call object, and call its execute () method to send the This request and get the data returned by the server into the incoming callback callback function.

    After that, you can directly process newCallback() when you use it, and override the onFailure and onResponse methods to process the callback content.

  3. The third is to learn to parse JSON data. In the project, we first have a general understanding of the request to the JSON data format, and then classify them. If it is a long-lasting class, you can inherit from litepal, and then parse the JSON data once and put it into the corresponding instance class and store it in the database, such as the list of provinces, cities and counties. The other party can create JSON for frequently changing information like weather information. The class corresponds to the JSON data. Note that the class in the JSON class should correspond to the corresponding internal class. For example, the Forecast contains the temperature, and the temperature contains the maximum and minimum. Therefore, the internal class is needed to represent the temperature in the forecast class. After all the JSON classes are constructed, a large class is needed for integration. For example, weather defines all of them. If you encounter duplicates, you can use the generic List.

  4. Regarding the use of fragments, when I started reading, I didn’t think the fragments were of any use. I felt that apart from being compatible with the tablet, it seemed to be of little use. It was similar to the usage of activities, but when I saw it integrated into the weather information page, I found its beauty. It turns out that his biggest role is to solve the repetitive application of some activities. The fragments can be used to edit multiple places at once, which can achieve the effect of similar activities, but also can be embedded everywhere like a control. For example, it is embedded in the sliding side of weather information in this project. In the sidebar, you can manipulate fragments like controls when you slide out.

  5. A little trick in Java is used here. The instanceof keyword can be used to determine whether an object belongs to an instance of a certain class. We call the getActivity() method in the fragment, and then cooperate with the instanceof keyword to easily determine whether the fragment is in MainActivity or WeatherActivity. If it is in MainActivity, then the processing logic remains unchanged. If it is in WeatherActivity, then close the sliding menu, display the pull-down refresh progress bar, and then request the weather information of the new city.

  6. The use of SwipeRefreshLayout pull-down refresh is mainly to wrap the layout that you want to implement the pull-down. The modified code is not too much. First, the instance of SwipeRefreshLayout is obtained in the onCreate() method, and then the setcolorschemeresources() method is called to set the pull-down refresh progress bar. colour. Then call the setOnRefreshListener() method to set a pull-down refresh listener. When the pull-down refresh operation is triggered, the onRefresh() method of this listener will be called back.

  7. The use of the service, the project uses the service to realize the background automatic refresh of the weather, and then the skill to create a timed task. In order to ensure that the software does not consume too much traffic, the time interval is set to 8 hours, and the onstartcommand( ) Method will be executed again. It is mainly divided into several steps: declaring service, creating service class, starting service and binding service. This part is also explained in detail in the official document. Which should pay attention to the binding service allows application components by calling bindService()its bound to create long-term connection, such as payment services pulled more. Such services are usually not allowed to component by calling startService()to start it.

  8. The last is the modification of the application icon and name, the packaging of the APP signature and the apk, and I learned that the App cannot be installed without signing.

  9. Learn to use git and github for project version management.

  10. After this project, I have conducted and summarized the various knowledge points learned before, and have a deeper understanding of the four major components of Android, and found many shortcomings. The next step is to learn more knowledge through more complex projects.

Guess you like

Origin blog.csdn.net/kilotwo/article/details/108438189