Kotlin Development Practises (Android)
1. App Link ↗
Secure and specific, Seamless user experience, Android Instant Apps support, Engage users from Google Search
<intent-filter android:autoVerify="true" tools:targetApi="m">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="arindamxd.github.io"
android:path="/main"
android:scheme="https" />
</intent-filter>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ATTENTION: This was auto-generated to handle app links.
val appLinkIntent = intent
val appLinkAction = appLinkIntent.action
val appLinkData = appLinkIntent.data
}
- Day 1: Synthetics
- Day 2: Null-safety
- Day 3: Null-check
- Day 4: Sealed Class ↗
- Day 5:
.use
Extension - Day 6: Mask Credit Card Number
- Day 7: Grocery Shopping
- Day 8: Immutability
- Day 9: Partition
- Day 10: Replace Deprecated Functions
- Day 11: Short and Group
- Day 12: Tail Recursion
- Day 13: Two Same Class Name
- Day 14: Vetoable
- Day 15: Serialization
- Day 16: Sorted By Functions
- Day 17: Sequences
- Day 18: Time Stamp & Zones Parsing
- Day 19: Delegation over Inheritance
- Day 20: Infix Function
- Day 21: Kotlin-Java Inter Operation
- Day 22: Destructuring Declarations
- Day 23: Operator Overloading
- Day 24: Jvm Static
- Day 25: Spread
3. Dynamic & Pinned Shortcuts ↗
Handling Dynamic & Pinned Shortcuts (Package)
Although you can publish up to five shortcuts (static and dynamic shortcuts combined) at a time for your app, most launchers can only display four. However, there is no limit to the number of pinned shortcuts to your app that users can create. Even though your app cannot remove pinned shortcuts, it can still disable them.
- Manifest: Meta Data
- Shortcut: XML
- Activities: OldActivity, NewActivity
4. Activity Alias Element ↗
So, in order to keep the shortcut on the home screen, even after the change in the Launcher Activity name, we use the concept of Activtiy-Alias.
- Manifest: <activity-alias>
LaunchActivity
5. Material Dark Theme ↗
Some of the most common benefits of a dark theme include conserving battery power for devices with OLED screens, reducing eye strain, and facilitating use in low-light environments. Starting with Android Q, users are now able to switch their device into dark theme via a new system setting, which applies to both the Android system UI and apps running on the device.
- Helper: ThemeHelper
- Activity: DayNightActivity
6. Coroutine Image Loader (COIL) ↗
- Fast: Coil performs a number of optimizations including memory and disk caching, downsampling the image in memory, re-using Bitmaps, automatically pausing/cancelling requests, and more.
- Lightweight: Coil adds ~1500 methods to your APK (for apps that already use OkHttp and Coroutines), which is comparable to Picasso and significantly less than Glide and Fresco.
- Easy to use: Coil's API leverages Kotlin's language features for simplicity and minimal boilerplate.
- Modern: Coil is Kotlin-first and uses modern libraries including Coroutines, OkHttp, Okio, and AndroidX Lifecycles.
- Activity: CoilActivity
7. The Bubble API (Android Q Preview) ↗
Bubbles are a new preview feature in Android Q, which let users easily multi-task from anywhere on their device.
Note: Bubbles are currently enabled for all users in the Q developer previews. In the final release, Bubbles will be available for developer use only.
- Bubbles take up screen real estate and cover other app content. You should only send a notification as a bubble if it is important enough such as ongoing communications, or if the user has explicitly requested a bubble for some content.
- Note that the bubble can be disabled by the user. In that case, a bubble notification is shown as a normal notification. You should always make sure your bubble notification works as a normal notification as well.
- Processes that are launched from a bubble (such as activities and dialogs) appear within the bubble container. This means a bubble can have a task stack. Things can get complicated if there is a lot of functionality or navigation within your bubble. We recommend keeping the functionality as specific and light-weight as possible.
- Manifest: <activity>
- Activity: BubbleActivity
7. Caching with RxJava Operators ↗
First, we need to understand why caching is useful? Caching is very useful in the following situations:
-
Reduce network calls: We can reduce the network calls by caching the network response.
-
Fetch the data very fast: We can fetch the data very fast if it is cached.
-
Activity:
Support it by clicking the ⭐ button on the upper right of this page. ✌️
Add many more features and bug fixes.
Copyright (C) 2019 Arindam Karmakar, Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
All pull requests are welcome, make sure to follow the contribution guidelines when you submit pull request.