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

Android Jetpack

Android Jetpack

Breve introducción a Android Jetpack y presentación de algunos Architecture Components y cómo los combinamos para potenciar nuestro desarrollo de aplicaciones.
Presentación en el marco del DevFest Buenos Aires 2019 , llevado a cabo en La Universidad Nacional de La Matanza

Jorge Nicolás Nogueiras

November 02, 2019
Tweet

More Decks by Jorge Nicolás Nogueiras

Other Decks in Programming

Transcript

  1. Android Jetpack Acelerando el desarrollo de tus apps Android Jorge

    Nogueiras nogueirasjn nogueiras Fabio Negri Fabio_negri fabionegri
  2. • Acelera el desarrollo • Elimina el código estándar •

    Crea apps sólidas y de alta calidad Ventajas
  3. UI

  4. <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools=“http://schemas.android.com/tools" android:id=“@+id/main_navigation_graph" app:startDestination=“@id/startFragment"> … </fragment> </navigation> <fragment

    android:id="@+id/startFragment" android:name="dev.nogueiras.navigation.StartFragment" android:label=“fragment_start" tools:layout="@layout/fragment_start"> <action android:id=“@+id/action_start_to_leaderboard" app:destination=“@id/leader_board_fragment”/> <action android:id=“@+id/action_start_to_new_game" app:destination=“@id/new_game_fragment”/> </fragment> <fragment android:id=“@+id/leader_board_fragment" android:name="dev.nogueiras.navigation.LeaderboardFragment" android:label=“fragment_leader_board" tools:layout=“@layout/fragment_leaderboard">
  5. <fragment android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:defaultNavHost="true"

    app:navGraph="@navigation/main_navigation_graph"/> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=“.presentation.StartActivity"> </androidx.constraintlayout.widget.ConstraintLayout>
  6. , bundle navigation.navigate(R.id.action_start_to_new_game } fun navigateToNewGame(attacker: User) { navigation =

    Navigation.findNavController(view) val bundle = bundleOf("user" to attacker) )
  7. } fun navigateToNewGame(attacker: User) { navigation = Navigation.findNavController(view) val action

    = LoginFragmentDirections.actionStartToNewGame(attacker) navigation.navigate(action)
  8. } fun navigateToNewGame(attacker: User) { navigation = Navigation.findNavController(view) val action

    = LoginFragmentDirections.actionStartToNewGame(attacker) navigation.navigate(action) intent?.extras?.let { val arguments = NewGameFragmentArgs.fromBundle(it) userLabel.text = arguments.user.username }
  9. • Nuestra UI siempre actualizada • Evita memory leaks y

    crashes • Permite compartir recursos
  10. • Mantiene el estado de la vista • Bajo acoplamiento

    con la vista • Sobrevive a cambios de configuración (ej: Rotación de pantalla)
  11. Application Data Access Objects Room Database Obtener DAOs Leer Entidades

    Persistir cambios Entities Leer/Guardar campos
  12. Entities @Entity(tableName = "users") data class User( val id: Long,

    val name: String ) @ColumnInfo(name = "id") @ColumnInfo(name = "name") @PrimaryKey
  13. Data Access Objects interface UserDao { fun getAll(): List<User> fun

    delete(user: User) } @Dao @Query("SELECT * FROM users") @Delete
  14. Room Database @Database( version = 1, entities = [User::class] )

    abstract class AppDatabase : RoomDatabase() { abstract fun userDao(): UserDao }
  15. // Ejecuto operación val allUsers = userDao.getAll() // Obtengo DAO

    val userDao = database.userDao() // Obtengo la base de datos val database = Room.databaseBuilder( applicationContext, AppDatabase::class.java, "trivia-game-db" ).build() Application