Posts with the tag Android:
It is very connivent to use any DI framework when all the objects required are available in application. For example, I have two classes Logger, Service and class Middleware is dependent on these classes.
class Logger()
class Service()
//this class requires Logger & Service object
class Middleware(private val logger:Logger. private val service:Service)
// middleware object
val middleware = Middleware(Logger(),Service())
Dagger can build objects of Logger and Service classes by indicating @Inject annotation to all three classes
internal class Logger @Inject constructor()
internal class Service @Inject constructor()
//this class requires Logger & Service object
internal class Middleware @Inject constructor(private val logger:Logger.
Below are widely used Dependency Injection frameworks mostly by android & Java application projects.
For Android application development, the suggested Framework by Google are Dagger and Hilt. These frameworks help to avoid writing boilerplate code.
Guice Guice (pronounced ‘juice’) is a lightweight dependency injection framework for Java 6 and above, brought to you by Google. (github.com)
With 10K stars this framework is mostly used by Java developers where Java is used for backend & Application development.
For Android, this framework is not suggested as this framework use reflections to scan annotations from code. This requires significant CPU cycles and RAM thus slowdowns application launch.
Recently, I developed an Android application. The application was developed focusing on simplicity. The application was small thus skipped writing unit tests. I know skipping the unit tests is not a good practice.
In past, I was working on backend projects where tons of unit tests exists for API’s. I am new to application development and spent some time to learn about MVC and MVVM design patterns.
For next project, the preference is MVVM. At end of this post I will share the reason to choose MVVM.
The example code for this post is written for Android application.
MVC (Model-View-Controller) Model: Model is data layer.
In this post, I am writing about how to setup Azure Active Directory Android application login to access Azure functions protected with Azure Active Directory authentication.
Create an Android Application Open Android Studio and create new Project with Empty Activity.
Configure project with below settings
Get SHA1 & package name Open powershell and cd to C:\Users<username>.android Execute below command, if prompted for password enter android or leave blank
keytool -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android
Copy SHA1 -> Navigate to https://base64.guru/converter/encode/hex and convert SHA1 to Base64
Copy package name from AndroidManifest.xml
Now you have packagename & Base64 SHA1 hash
Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard.
Steps to enable checkstyle for Android Project Create checkstyle.xml Create folder checkstyle inside Android Project app folder. Create file checkstyle.xml Reference
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<!--
Checkstyle configuration that checks the sun coding conventions from:
- the Java Language Specification at
http://java.sun.com/docs/books/jls/second_edition/html/index.html
- the Sun Code Conventions at http://java.sun.com/docs/codeconv/
- the Javadoc guidelines at
http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
- the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
- some best practices
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.