Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Basic of Android Development

Basic of Android Development

Basic information about android development with a code lab to build your first Koltin app.

Avatar for Laurence de Villers

Laurence de Villers

November 21, 2018
Tweet

More Decks by Laurence de Villers

Other Decks in Technology

Transcript

  1. Basic of Android • Android Apps are written in Java

    and Kotlin • UI Screens are defined in XML • IDE Android Studio ( base on Intellij ) ◦ Android SDK ◦ Android Monitor • Terminal Commands (adb) • Apps run in a Virtual Marchine • Android Kernel is the Linex Kernel • Build tool is Gradle • App format = .apk
  2. Code Definition and Examples Ressources • developer.android.com • Udacity (Android

    for Beginners and Android MicroDegree) • Android Arsenal ( Android developer portal with tools, libraries, and apps) • CodeLab: https://codelabs.developers.google.com/?cat=Android • Vocab : https://developers.google.com/android/for-all/vocab-words/
  3. Basic of Kotlin What is Kotlin Is a language developed

    by JetBrains. 100% interoperable with Java A language that have Null Safety var b: String? = "abc" b = null // ok val l = b.length // error WHY? variable 'b' can be null var a: String = "abc" a = null // compilation error val l = a.length //ok
  4. Basic of Kotlin Safe Call Operator, witten ?. // If

    'applETS' or 'applETS.mobileapp' is null the function is not called: applETS?.mobileapp?.android = creationOfAndroidMobileApp() val a = "Kotlin" val b: String? = null println(b?.length) println(a?.length) Safe Call can be chains Elvis Operator, witten ?: val l = b?.length ?: -1 In Java int l = b != null ? b.length : -1
  5. Basic of Kotlin The !! Operator val l = b!!.length

    Safe Cast val aInt: Int? = a as? Int val VS var val is immutable same as the final modifier in java var is mutable (can be reassigned)
  6. Android KTX Part of Jetpack Concise, readable code. A suite

    of libraries Android KTX, Testing KTX, ...
  7. View Groups ( Layout) • ConstraintLayout • CoordinatorLayout • RelativeLayout

    • LinearLayout • ListView • RecyclerView • ScrollView • CardView • etc.
  8. Retains value between onCreate and onDestroy // some transient state

    for the activity instance var gameState: String? = null override fun onCreate(savedInstanceState: Bundle?) { // call the super class onCreate to complete the creation of activity like // the view hierarchy super.onCreate(savedInstanceState) // recovering the instance state gameState = savedInstanceState?.getString(GAME_STATE_KEY) // set the user interface layout for this activity // the layout file is defined in the project res/layout/main_activity.xml file setContentView(R.layout.activity_main) }
  9. Retains value between onCreate and onDestroy // We restore some

    state in onCreate(), while we can optionally restore // other state here, possibly usable after onStart() has completed. // The savedInstanceState Bundle is same as the one used in onCreate(). override fun onRestoreInstanceState(savedInstanceState: Bundle?) { textView.text = savedInstanceState?.getString(TEXT_VIEW_KEY) } // invoked when the activity may be temporarily destroyed (onStop), save the instance state here override fun onSaveInstanceState(outState: Bundle?) { outState?.run { putString(GAME_STATE_KEY, gameState) putString(TEXT_VIEW_KEY, textView.text.toString()) } // call superclass to save any view hierarchy super.onSaveInstanceState(outState) }
  10. Gadle Custom build tool used to build android packages android

    { compileSdkVersion 28 defaultConfig { applicationId "com.ldevillers.applets_first_app" minSdkVersion 16 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.android.support:appcompat-v7:28.0.0' … }
  11. Want to learn more about Android ? Join the meetup

    GDG Montreal Android: android-montreal.com