WorkManager 란?

여러 개의 백그라운드 작업을 조건에 따라 스케쥴링 하고 상태 체크, 취소 등의 작업을 쉽게 할 수 있도록 도와주는 라이브러리

백그라운드 작업

  • 유저 입장에서 보면 눈에 보이지 않게 이뤄지는 작업
  • 쓰레드 개념으로 보면 메인쓰레드(UI 쓰레드) 가 아닌 쓰레드에서 동작하는 작업
  • 알람매니저, 서비스 등의 안드로이드 컴포넌트를 통해 실행되는 작업
  • API 호출, DB 쿼리, 데이터 동기화, 로깅, 미디어 업로드, 폴링, 백그라운드 음악 재생, 이미지 프로세싱

백그라운드 작업을 특성에 따라 구분

그럼 WorkManager 를 어디에 써야 하나?

미룰수 있는 일 | 실행이 보장되어야 하는 일


사용하기




Constraint

WorkRequest 생성(worker 와 constraints 결합)

생성한 workrequest 를 WorkManager에 enqueue

WorkRequest 의 상태 체크하기

WorkRequest 반복되는 작업 만들기

병렬실행

순차실행

콤보

그룹핑

'Android > Android Develop' 카테고리의 다른 글

Android Navigation  (0) 2019.07.07
Android Slice  (0) 2019.07.07
Instant App  (0) 2019.07.07
Android Notification 개발시 주의사항  (0) 2019.07.07

Navigation 의 의미

기존 문제점

  • exception 에 잘 정돈된 fragment transactions 을 어떻게 할 것인가
  • 앱의 여러 위치에 어떻게 deep link 를 만들고 최신화할 것인가
  • argument bundle 을 어떻게 안전하게 전달할 것인가
  • up and back 이 어떻게 사용자가 원하는 방식으로 동작할 것인가
    • 특히 deep link 로 앱에 들어올 경우 back stack 을 어떻게 조절할 것인가
  • 기존의 errorprone boilerplate code 를 어떻게 없앨 것인가
  • 잘 동작하는지 어떻게 Testing 할 것인가

Navigation 이 할 수 있는 일

  • Handling fragment transactions
  • Deep linking is a first class operation
  • Type safety when passing information while navigating
  • Handling up and back correctly by default
  • Provides defaults for animations and transitions
  • Navigation UI patterns like navigationn drawers and bottom nav with little additional work
  • Android Studio offers tooling for visualizing and editing the navigation flow of an app

Navigation 사용





NavHostFragment implements NavHost

a widget that is meant to swap in and out different fragment destinations as you navigate through the navigation graph


NavigationUI(navigation-ui-ktx)

collection of static methods that associate menu items with navigation destinations
destination id를 id로 가진 menu item 을 누를 경우 해당 destination 으로 이동 시켜줌



NavController


NavOptions

Safe Args




Deep Linking



'Android > Android Develop' 카테고리의 다른 글

WorkManager  (0) 2019.07.07
Android Slice  (0) 2019.07.07
Instant App  (0) 2019.07.07
Android Notification 개발시 주의사항  (0) 2019.07.07

Slices 란?

Android's new approach for remote content

  • Tempalted
  • Interactive
  • Updateable
    Backwards-compatible through KitKat/API 19+ (95% of devices)

The Goal?

Reusable API to generalize for how we present remote app content in Android
Slice를 하나의 재사용 가능한 API 로 만들어서 안드로이드 내에서 원격 컨텐츠를 일반적으로 사용할 수 있게 하기 위함

Slice 사용

Define your SliceProvider in AndroidManifest

    ...
    <!-- Slices definition -->
    <provider anroid:name=".MySliceProvider"
        android:authority="com.example.slicesample"
        android:exported="true"
    </provider>
    ...

Implement your SliceProvider

    class MySliceProvider : SliceProvider() {
        fun onBindSlice(uri: Uri) : Slice ? {
            if(uri.path == "/wifi") {
                rturn buildWifiSlice(uri)
            } else if(uri.path == "/alarms") {
                rturn buildAlarmsSlice(uri)
            } else if(uri.path == "/nightlight") {
                rturn buildNightLightSlice(uri)
            }
            ...
            return null
        }

        ...
        fun buildWifiSlice(sliceUri: uri) : slice {
            val listBuilder =
                ListBuilder(getContext(), sliceUri, INFINITY)

            val row = RowBuilder(listBuilder).setTitle("Wi-fi");

            if(!isWifiStateLoaded) {
                loadWifiState()
                row.setSubtitle(null, true /* isLoading */)
                    .addEndItem(null, true /* isLoading */)
            } else {
                ...
            }

            listBuilder.addRow(row)
            return listBuilder.build()
        }
        ...
    }

'Android > Android Develop' 카테고리의 다른 글

WorkManager  (0) 2019.07.07
Android Navigation  (0) 2019.07.07
Instant App  (0) 2019.07.07
Android Notification 개발시 주의사항  (0) 2019.07.07

인스턴트앱 이란?

  • 설치 없이 실행 가능한 앱 - 설치화면으로 보여주는 대신, 앱의 일부 기능을 경험할 수 있다
  • Google Play 나 모바일 웹에서 인스턴트앱을 실행할 수 있다
  • 필요시 설치화면으로 보여줄 수 있다

앱 링크 제공

  • 모바일 웹에서 링크를 클릭했을 때 진입할 액티비티에 인텐트 필터를 설정

  • 앱 링크는 별도의 인증절차를 거쳐야 한다

      <intent-filter>
          <action android:name="anroid.intent.action.ViEW" />
          <category android:name="anroid.intent.category.DEFAULT" />
          <category android:name="anroid.intent.category.BROWSABLE" />
          <data android:scheme="http" android:host="www.example.com" />
          <data android:scheme="https"
      </intent-filter>

    모듈 분리 (4MB size 제한)

    • 인스턴트 앱이 실행될 때 Google Play 에서 일부 기능을 위한 모듈을 다운받는다
    • 필요한 기능만 다운받을 수 있도록 프로젝트를 기능별 모듈로 분리해야 한다
    • Base Feature, Feature 로 분리 (각각의 Feature 들은 BaseFeature 에 의존성을 가진다)
    • 어떤 부분을 Base 로 잡을지 고민을 많이 해야됨
    • 4MB 크기 제한은 크리티컬함

    인스턴트 앱에서 지원되는 권한 문제

    • 지원되는 권한들의 제한적임 (예: VOD 앱에서 READ_PHONE_STATE, READ_EXTERNAL_STORAGE 등 요청할 경우 거절됨)
    • 인스턴트 앱 내의 통신은 모두 https 만 가능

    모듈간의 의존성 때문에 gradle 관리가 힘들다 - gradle sync 문제가 빈번함

    데이터바인딩 지원이 안된다

    백그라운드 작업 제한 - 로컬 웹서버 실행할 수 없음

'Android > Android Develop' 카테고리의 다른 글

WorkManager  (0) 2019.07.07
Android Navigation  (0) 2019.07.07
Android Slice  (0) 2019.07.07
Android Notification 개발시 주의사항  (0) 2019.07.07

Android Api 버전별로 다른 동작의 notification 을 만들려면 Action 을 이용함

NotificationCompat.Action(int icon, CharactorSequence title, PendingIntent intent)

Large icon 을 설정하면 버전별로 각각 다른 위치에 아이콘이 보이게 된다

단순구현

    public Notification getNotification(Context context) {
        return new NotificationCompat.Builder(context, getName())
            .setSmallIcon(R.drawable.noti_status_icon)
            .setColor(Color.GREEN)
            .setContentTitle("content title area")
            .setProgress(100, 0, true)
            .setLargeIcon(getBitmapFromResource(context, R.drawable.badge_gift))
            .setShowWhen(false)
            .addAction(new NotificationCompat.Action(R.drawable.star, "star", null))
            .addAction(new NotificationCompat.Action(R.drawable.check, "check", null))
            .build();
    }

OS 버전별로 다른 Notification 배경 색상

    <TextView
        style="@style/TextAppearance.Compat.Notification.Title"
        ... />

    // 버전별로 분기해서 style 을 만들어 놓음
    TextAppearance.Compat.Notification.Title(.../values/values.xml)

기본 icon 활용

    android.R.drawable.stat_sys_download
    android.R.drawable.stat_sys_download_done

Create a fully custom notification layout - Full custom layout 을 만드는 경우

  • setStyle() 을 호출하면 안됨
  • OS >= 7.0 인 경우 DecoratedCustomViewStyle() 적용
  • OS >= 7.0 인 경우 Padding 이 자동으로 들어가는 점 고려

Grouping

    .setGroupSummary(true)

Channel : 채널

  • Android O 이상부터는 채널 적용해야 Notification 정상 노출

  • 개발자는 Notification 에 채널을 할당하고

  • 사용자는 채널에 있는 Notification 들에 대해 개별 설정을 할 수 있음

      if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          notificationManager.createNotificationChannel(new NotificationChannel(
              "channelId",
              "channelName"
              NotificationManager.IMPORTANCE_DEFAULT));
      }
      notificationManager.notify(ordinal(), notification);
    
      public Notification getNotification(Context context) {
          return new NotificationCompat.Builder(context, getName())
              .setSmallIcon(R.drawable.noti_status_icon)
              .setColor(Color.GREEN)
              .setGroup(GROUP_NAME)
              .setChannelId("channelId")
              .setContentTitle("channel test")
              .build();
      }

'Android > Android Develop' 카테고리의 다른 글

WorkManager  (0) 2019.07.07
Android Navigation  (0) 2019.07.07
Android Slice  (0) 2019.07.07
Instant App  (0) 2019.07.07

+ Recent posts