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

Android Jetpack - Roadshow IDCAMP Tangerang

1fe3e1b3343b555b0a195180607fbd6a?s=47 Ahmad Arif Faizin
October 03, 2019
5

Android Jetpack - Roadshow IDCAMP Tangerang

Indosat Ooredoo Digital Camp (IDCamp) adalah bagian dari Indosat Ooredoo Future Digital Economy Lab, sebuah program beasiswa dari Indosat Ooredoo untuk mencetak developer/programmer muda Indonesia yang siap bersaing di dunia ekonomi digital.

1fe3e1b3343b555b0a195180607fbd6a?s=128

Ahmad Arif Faizin

October 03, 2019
Tweet

Transcript

  1. The Best Way to Become an Android Developer Expert with

    Android Jetpack Ahmad Arif Faizin Academy Content Writer at Dicoding
  2. None
  3. None
  4. None
  5. Do You Know?

  6. None
  7. None
  8. None
  9. None
  10. None
  11. Let’s Listen Their Story

  12. dicoding.id/junia

  13. dicoding.id/junia

  14. dicoding.id/junia

  15. dicoding.id/junia

  16. dicoding.id/rosy

  17. dicoding.id/rosy

  18. dicoding.id/hastu

  19. dicoding.id/hastu

  20. dicoding.id/hastu

  21. What about us?

  22. How to be Developers?

  23. None
  24. None
  25. Jetpack? Kiri, Kanan, L1, L2, R1, R2, Atas, Bawah, Kiri,

    Kanan
  26. None
  27. Android Jetpack Jetpack is a collection of Android software components

    to make it easier for you to develop great Android apps.
  28. Advantages Accelerate development Eliminate boilerplate code Build high quality, robust

    apps
  29. None
  30. None
  31. None
  32. Layouting LinearLayout ConstraintLayout RelativeLayout GridLayout ScrollView

  33. Constraint Layout VS Other Layout

  34. Passing Data between Activity

  35. Activity vs Fragment

  36. Navigation

  37. Using Library to Load Image Glide Picasso Pro Tips!

  38. Android Debugging

  39. First Step... + =

  40. None
  41. None
  42. Android Networking - get data from API Fast Android Networking

    Retrofit Volley AQuery
  43. None
  44. Behavior - Notifications Reply & Deep Link action, Bubble, Interruptive

    & Gentle Notification Status bar and notification drawer Heads-up notification
  45. Notification Channel On and above Android 8.0 (Oreo) if (Build.VERSION.SDK_INT

    >= Build.VERSION_CODES.O) { val channel = NotificationChannel( CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT) mBuilder.setChannelId(CHANNEL_ID) mNotificationManager.createNotificationChannel(channel) }
  46. Behavior - Permissions Compatibility APIs for checking and requesting app

    permissions <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.snazzyapp"> <uses-permission android:name="android.permission.SEND_SMS"/> <application ...> ... </application> </manifest>
  47. if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, Manifest.permission.READ_CONTACTS)) {

    } else { ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_CONTACTS}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); } } else { // Permission has already been granted } Request Permission Flow
  48. Permissions.check(this/*context*/, Manifest.permission.CALL_PHONE, null, new PermissionHandler() { @Override public void onGranted()

    { // do your task. } }); Pro Tips! Permission using Library Android Permissions https://github.com/nabinbhandari/Android-Permissions
  49. Behavior - Preferences Create interactive settings screens <androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> <SwitchPreferenceCompat

    app:key="notifications" app:title="Enable message notifications"/> <Preference app:key="feedback" app:title="Send feedback" app:summary="Report technical issues or suggest new features"/> </androidx.preference.PreferenceScreen>
  50. Data Persistence

  51. Foundation - Testing An Android testing framework for unit and

    runtime UI tests
  52. Foundation - Testing An Android testing framework for unit and

    runtime UI tests
  53. Foundation - Unit Test Getting Started dependencies { // Required

    -- JUnit 4 framework testImplementation 'junit:junit:4.12' // Optional -- Robolectric environment testImplementation 'androidx.test:core:1.0.0' // Optional -- Mockito framework testImplementation 'org.mockito:mockito-core:1.10.19' }
  54. Foundation - Instrumental Testing Getting Started dependencies { androidTestImplementation 'androidx.test:runner:1.1.0'

    androidTestImplementation 'androidx.test:rules:1.1.0' // Optional -- Hamcrest library androidTestImplementation 'org.hamcrest:hamcrest-library:1.3' // Optional -- UI testing with Espresso androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' // Optional -- UI testing with UI Automator androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' }
  55. None
  56. Pro Tips!

  57. None
  58. None
  59. Architecture Pattern

  60. Architecture Pattern • Maintainability • Testability • Extensibility

  61. None
  62. Architecture Component Lifecycle - ViewModel - LiveData -Room

  63. Repository Benefit

  64. Architecture - ViewModel Manage UI-related data in a lifecycle-conscious way

  65. Architecture - LiveData Ensures your UI matches your data state

    No memory leaks No crashes due to stopped activities No more manual lifecycle handling Always up to date data Proper configuration changes Sharing resources Notify views when underlying database changes
  66. None
  67. Architecture - LiveData public class NameViewModel extends ViewModel { //

    Create a LiveData with a String private MutableLiveData<String> currentName; public MutableLiveData<String> getCurrentName() { if (currentName == null) { currentName = new MutableLiveData<String>(); } return currentName; } // Rest of the ViewModel... } Notify views when underlying database changes
  68. public class NameActivity extends AppCompatActivity { private NameViewModel model; @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Other code to setup the activity... // Get the ViewModel. model = ViewModelProviders.of(this).get(NameViewModel.class); // Create the observer which updates the UI. final Observer<String> nameObserver = new Observer<String>() { @Override public void onChanged(@Nullable final String newName) { // Update the UI, in this case, a TextView. nameTextView.setText(newName); } }; // Observe the LiveData, passing in this activity as the LifecycleOwner and the observer. model.getCurrentName().observe(this, nameObserver); } }
  69. Architecture - Room Fluent SQLite database access

  70. SQLite Vs Room Create database table @Entity public class User

    { @PrimaryKey public int uid; @ColumnInfo(name = "first_name") public String firstName; @ColumnInfo(name = "last_name") public String lastName; } private static final String WORD_LIST_TABLE_CREATE = "CREATE TABLE " +WORD_LIST_TABLE + " (" + UID + " INTEGER PRIMARY KEY, " + FIRST_NAME + " TEXT, ” + LAST_NAME + " TEXT );";
  71. Architecture - Room Entity @Entity public class User { @PrimaryKey

    public int uid; @ColumnInfo(name = "first_name") public String firstName; @ColumnInfo(name = "last_name") public String lastName; }
  72. Architecture - Room Dao @Dao public interface UserDao { @Query("SELECT

    * FROM user") List<User> getAll(); @Query("SELECT * FROM user WHERE uid IN (:userIds)") List<User> loadAllByIds(int[] userIds); @Query("SELECT * FROM user WHERE first_name LIKE :first AND " + "last_name LIKE :last LIMIT 1") User findByName(String first, String last); @Insert void insertAll(User... users); @Delete void delete(User user); }
  73. Architecture - Room Database @Database(entities = {User.class}, version = 1)

    public abstract class AppDatabase extends RoomDatabase { public abstract UserDao userDao(); } Create Database AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "database-name").build();
  74. Architecture - Paging Gradually load information on demand from your

    data source
  75. None
  76. Architecture - Paging Gradually load information on demand from your

    data source DataSource @Dao public interface ConcertDao { // The Integer type parameter tells Room to use a // PositionalDataSource object. @Query("SELECT * FROM concerts ORDER BY date DESC") DataSource.Factory<Integer, Concert> concertsByDate(); }
  77. Architecture - Paging Gradually load information on demand from your

    data source PagedList public class ConcertViewModel extends ViewModel { private ConcertDao concertDao; public final LiveData<PagedList<Concert>> concertList; // Creates a PagedList object with 50 items per page. public ConcertViewModel(ConcertDao concertDao) { this.concertDao = concertDao; concertList = new LivePagedListBuilder<>( concertDao.concertsByDate(), 50).build(); } }
  78. Architecture - Paging Gradually load information on demand from your

    data source UI public class BookmarkPagedAdapter extends PagedListAdapter<DataModel, ViewHolder> { ... }
  79. Architecture - WorkManager Best practice to handling background process

  80. None
  81. Architecture - WorkManager public class UploadWorker extends Worker { public

    UploadWorker(@NonNull Context context, @NonNull WorkerParameters params) { super(context, params); } @Override public Result doWork() { // Do the work here--in this case, upload the images. uploadImages() // Indicate whether the task finished successfully with the Result return Result.success() } } Manage your Android background jobs
  82. Architecture - WorkManager OneTimeWorkRequest OneTimeWorkRequest uploadWorkRequest = new OneTimeWorkRequest.Builder(UploadWorker.class).build() PeriodicWorkRequest

    Constraints constraints = new Constraints.Builder().setRequiresCharging(true).build(); PeriodicWorkRequest saveRequest = new PeriodicWorkRequest.Builder(SaveImageFileWorker.class, 1, TimeUnit.HOURS).setConstraints(constraints).build(); WorkManager.getInstance().enqueue(saveRequest); Manage your Android background jobs
  83. Architecture - WorkManager Manage your Android background jobs WorkContinuation chain1

    = WorkManager.getInstance() .beginWith(workA) .then(workB); WorkContinuation chain2 = WorkManager.getInstance() .beginWith(workC) .then(workD); WorkContinuation chain3 = WorkContinuation .combine(Arrays.asList(chain1, chain2)) .then(workE); chain3.enqueue();
  84. Documentation g.co/jetpack Try Sample App https://github.com/googlesamples/ android-sunflower

  85. What’s next?

  86. Skripsi TA Bimbingan Tugas Besar Deadline Project Doi ngambek Rapat

    Kerja
  87. None
  88. Sertifikat / Sertifikasi Kebutuhan Industri IT Talenta Digital Lulusan universitas

    Lulusan SMK Otodidak Kursus Profesional dll (re-skilling) Training / Matrikulasi Sertifikasi
  89. None
  90. None
  91. https://idcamp.indosatooredoo.com/

  92. None
  93. None
  94. VS

  95. —IMAM SYAFI’I Jika kamu tidak sanggup menahan lelahnya belajar maka

    kamu harus sanggup menahan perihnya kebodohan
  96. Thank You...

  97. 97 Ahmad Arif Faizin 0857 4048 2440 @arif_faizin arif@dicoding.com