Thursday, 12 December 2019

Null Safety


!! Not-null Assertion //use it when you are sure the value is notnull
//throws nullpointerexception if the value is found to be null

?.let{} safe call with let

?. Safe call operator
Val name: String = null
By default kotlin not support nullable.
If we want to assign null we can use -> Val name: String? = null

?.let{} safe call with let
//1. returns the length if the name is not null else return null
//2. Name?.let{//It Executes the block only if the name is notnull
Println("")
}
?: Elvis
// when we have a nullable reference name, we can say "is name is not null",use it ,
//otherwise use some non nullable value
  1. Val nameLen=if(name!=null)
Name.length
Else
-1
Or
Val leng = name?.length?: -1

Wednesday, 4 December 2019

Difference between DP , SP ,DPI and Pixel


DPI- Dots per Inch
DP - Density independent pixels—>it scales as per device screen density—>used to define layouts or views dimension—>pixel unit I.e independent of density of the device screen
Px- Pixel

SP: scale independent pixel—>used only for textview size—>it scales as per device screen density and user setting preferences.

px= dp*(dpi/160)

1dp equals to how many pixel for mdpi
Here mdpi = 160 pixel
         hdpi=  240 pixel
        Xhdpi = 320 pixel
xxhdpi=480 pixel


Px = 1*160/160

Px =1dp

For hdpi=1px=1*240/160=1.5px—>scale factor

Screen size measured in diagonally- 5.0’ screen
Screen resolution 720*1280 pixels

Screen density measured in DPI(Dots per Inch)
        mdpi = 160 pixel
         hdpi=  240 pixel
        Xhdpi = 320 pixel
xxhdpi=480 pixel