This is the 18th day of my participation in the August Genwen Challenge.More challenges in August
This chapter learns about the Android version.
The Android SDK version
You can view it in the Android Studio “New Project” wizard.
Each release with a release code is followed by an incremental release.
For more information on Android distribution, see the official website:
Developer.android.com/about/dashb…
Android programming and compatibility issues
Up to now, Android has been released a lot of versions, this summary is mainly about compatibility problems, look at the summary of the figure, the distribution of the current Android platform version, development is not compatible with the most original version, after all, the use of a small proportion, reduce the point of development compatibility difficulty. If you look at the picture, compatibility to 4.4 is 98% compatible.
As for the compatibility of UI layout, you can use the configuration modifier to fix it. As for the compatibility of so many versions, Google provides some compatibility libraries, which has reduced the difficulty of development.
Open the build.gradle file under the application module and see compileSdkVersion, minSdkVersion and targetSdkVersion
SDK Minimum Version (minSdkVersion)
If the lowest version is set as the standard, the operating system will refuse to install applications on devices whose OS version is lower than the standard.
SDK targetSdkVersion
In general, the target version is the latest release of Android, in order to tell Android which API level the application is designed for.
SDK compileSdkVersion
The lowest and target SDK versions are notified to the operating system, while SDK builds are private information between you and the compiler. It does not appear in the manifest configuration file. The best choice for the compile target is the latest API level.
Safely add code from the new version of the API
-
Due to the large difference between the lowest version of the SDK and the compiled version of a typical application, if you call the new version of the code on an older version of the system, the application will crash.
-
Android Lint, however, can now detect this potential problem with a warning like Call requires API Level 21 (Current min is 19).
-
The solution to the problem is to upgrade the lowest version of the SDK, but this only sidesteps the compatibility issue. The recommended solution is to put the high API level code in a conditional statement that checks the version of the Android device.
Such as:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
...
}
Copy the code
-
The build.version. SDK_INT constant represents the VERSION number of the Android device. The version number list – developer.android.com/reference/a…
-
The ActivityOptions class is used to customize how to start an activity by calling makeClipRevealAnimation(…). Let CheatActivity appear when the drawing effect, this is the Android SDK API level 23 added method, so there will be a wavy line error, at this time we need to judge the version number to compatible.
Here is another tip, in order for the human eye to see the animation effect of the activity switch, you can enter the mobile system’s developer option, increase the transition animation zoom time by 5 times, so that you can obviously feel the animation! Practical oh!
JETPACK library
While it is useful to determine the API level that executes different code logic, it is not the best approach.
The reason:
- It’s a lot of work for developers to adapt to different system versions
- The experience of running the same app on different devices can vary greatly
The Jetpack library recommended by Google supports backward compatibility with new features to keep the user experience as consistent as possible between old and new devices. The AndroidX library file is a modified version of the previous support library. Whenever possible, use them. Although it is still not perfect, but it will be improved step by step, if it is just met with no compatible on their own project problems, obediently write judgment code.
To save compatibility code, you can use the ActivityOptionsCompat class in AndroidX to achieve the same effect:
/ / to peek at the answers mBinding. BtnCheat. SetOnClickListener {val answer. = quizViewModel currentQuestionAnswer val option = ActivityOptionsCompat.makeClipRevealAnimation(it, 0, 0, it.width, it.height) startForResult.launch(CheatActivity.newIntent(this, answer), option) }Copy the code
For details, see the Github address of Demo at the end.
Use the Android developer documentation
The Android SDK has a huge amount of information, plus it’s constantly updated, and almost no one can remember everything about it, so it’s important to consult the SDK documentation and keep learning new things.
Address: developer.android.com/
- Platform: Basic platform information, focusing on basic platform support and different versions of Android.
- Android Studio: Documentation related to development tools, which describes different development tools and processes to facilitate development.
- Google Play: Guidelines and tips to help you deploy your app and make your app more popular with your users.
- Jetpack: Introduce the Jetpack library and how the Android team is working to improve the development experience. This book uses only part of the Jetpack library, and I recommend learning the entire library.
- Kotlin: Kotlin language tutorials and tips.
- Documentation: Developer documentation home page.
- News: The latest articles and news feeds to keep up with the latest developments in Android development.
Challenge exercise: Report the compiled version
TextView layout, this part of the code is not pasted, then get the TextView in the KT code, assign it to the current compiled version.
mBinding.tvCompileVersion.text = "API LEVER = ${Build.VERSION.SDK_INT}"
Copy the code
Challenge exercise: Limit the number of cheats
Allows users to cheat up to three times. CHEAT! Record the number of times users peek at the CHEAT! The remaining times are displayed under the button. After exceeding, disable the peep button.
- First, add the Cheat button and then add TextView to show the number of peeks.
- The number of peeks is managed by viewModel, which is bound to the activity life cycle. Every time you peek back, the number of peeks will be increased by one, and the PAGE UI display will be updated until you can no longer peek. Set the Cheat button as unclickable. Note, of course, that the system killed the activity, so the flag should also be stored in onSaveInstanceState().
Solution as above, specific code Demo address:
Github.com/visiongem/A…
other
At present, the GeoQuiz project has been completed, and I will start to learn other projects and knowledge points later. Yeah, yeah, yeah ~ initial mission completed! Of course, it still has many shortcomings, there is time to optimize optimization, but also for skilled knowledge points. Practice always pays off! Come on! 🆙
🌈 follow me ac~ ❤️
Public account: Ni K Ni K