Looking for easy to follow code to understand Fragments in Android ? You're at right place ! Checkout this sample code in github: https://github.com/ptyagi911/android-fragments-example
Android supported Java8 features
- default and static methods in Interfaces
- default and static methods can be declared in Interfaces declarations. These methods don't need to be implemented by the Classes that are implementing those interfaces. static methods are attached to the Interface and Classes which implements such interfaces.
- Reference: https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
- Repeating Annotations
- Now one annotation can be used multiple times on a specific target.
- Reference: https://docs.oracle.com/javase/tutorial/java/annotations/repeating.html
- Lambda expressions:
- Lambda expressions enable to treat functionality as method argument or code as data.
- Lambda exp is useful especially to define anonymous class with one method
- Reference: https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
- Syntax for Lambda expressions: https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html#syntax
Terms:
- Functional interfaces: An interface with only method is called as functional interfaces. JDK defines few built-in functional interfaces in package: java.util.function
How to setup Signing configuration in Android Studio/Gradle
Add following to your build.gradle :
android {
defaultConfig {}
signingConfigs { release { storeFile file("<path-to-signing-keys>/signingKeys.jks") storePassword "your store password" keyAlias "your chosen alias" keyPassword "password" }
}You can also publish to playtore by adding following configuration to your build.gradle:play { serviceAccountEmail = 'serviceAccount@gmail.com' pk12File = file('key.p12') track = 'alpha'}
Starting android emulator using commandline
Emulator can be started using command line using:
emulator -avd <name>
Android Testing using ATSL (Android Testing Support Library)
Running instrumented unit tests
Instrumented unit tests are important when a functionality can't be tested using mock objects.
Tools used
AndroidJunitRunner is used to run such tests.
Configuring build.gradle
defaultConfig {Dependencies
applicationId "appId" minSdkVersion 17 targetSdkVersion 23 versionCode 1
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}
dependencies {Running Instrument tests:
compile 'com.android.support:support-annotations:23.0.1' compile 'com.android.support:appcompat-v7:23.0.1'
androidTestCompile 'junit:junit:4.12' androidTestCompile 'com.android.support:support-annotations:23.0.1' androidTestCompile 'com.android.support.test:runner:0.4.1' androidTestCompile 'com.android.support.test:rules:0.4.1'
}
gradlew connectedAndroidTest
Useful links:
How to access build version from build.gradle from Java class
Its available in BuildConfig.java.
So simply access version name like this:
And Version code could be accessed like this:
So simply access version name like this:
BuildConfig.VERSION_NAME
And Version code could be accessed like this:
BuildConfig.VERSION_CODE
Subscribe to:
Posts (Atom)
Scheduling Repeating Local Notifications using Alarm Manager
Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .
-
I've been struggling to get this working for about 2 days now. I was able to POST a request directly from sockets, but it took me a whi...
-
Couple of days ago, I started using Google's code projects for Git as well. It required me to setup and use .netrc file. Here are steps...
-
Okay, so I wanted to use Hex.encodeHexString method from org.apache.commons.codec.binary.Hex (commons-codec-1.6.jar) library to generate...