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

Android Jetpack - Roadshow IDCAMP Tangerang

Ahmad Arif Faizin
October 03, 2019
45

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.

Ahmad Arif Faizin

October 03, 2019
Tweet

More Decks by Ahmad Arif Faizin

Transcript

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

    Android Jetpack Ahmad Arif Faizin Academy Content Writer at Dicoding
  2. Android Jetpack Jetpack is a collection of Android software components

    to make it easier for you to develop great Android apps.
  3. Behavior - Notifications Reply & Deep Link action, Bubble, Interruptive

    & Gentle Notification Status bar and notification drawer Heads-up notification
  4. 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) }
  5. 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>
  6. 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
  7. 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
  8. 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>
  9. 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' }
  10. 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' }
  11. 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
  12. 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
  13. 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); } }
  14. 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 );";
  15. 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; }
  16. 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); }
  17. 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();
  18. 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(); }
  19. 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(); } }
  20. Architecture - Paging Gradually load information on demand from your

    data source UI public class BookmarkPagedAdapter extends PagedListAdapter<DataModel, ViewHolder> { ... }
  21. 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
  22. 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
  23. 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();
  24. Sertifikat / Sertifikasi Kebutuhan Industri IT Talenta Digital Lulusan universitas

    Lulusan SMK Otodidak Kursus Profesional dll (re-skilling) Training / Matrikulasi Sertifikasi
  25. VS

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

    kamu harus sanggup menahan perihnya kebodohan