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

What's new Android 12

What's new Android 12

star_zero

June 20, 2021
Tweet

More Decks by star_zero

Other Decks in Programming

Transcript

  1. 4 override fun onCreate(savedInstanceState: Bundle?) { // ... val content:

    View = findViewById(android.R.id.content) content.viewTreeObserver.addOnPreDrawListener( object : ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { return if (viewModel.isReady) { // 準備完了 content.viewTreeObserver.removeOnPreDrawListener(this) true } else { // 準備中 false } } } ) }
  2. 5 override fun onCreate(savedInstanceState: Bundle?) { // ... splashScreen.setOnExitAnimationListener {

    splashScreenView -> val animation = ObjectAnimator.ofFloat( /* ... */) animation.duration = 200L animation.doOnEnd { splashScreenView.remove() } animation.start() } }
  3. 11 // CheckBox remoteView.setCompoundButtonChecked(R.id.check, true) // RadioGroup remoteView.setRadioGroupChecked(R.id.radio_group, R.id.radio_1) //

    Checkイベント remoteView.setOnCheckedChangeResponse( R.id.check, RemoteViews.RemoteResponse.fromPendingIntent(pendingIntent) )
  4. 13 val listView = RemoteViews(...) val gridView = RemoteViews(...) val

    viewMapping = mapOf( SizeF(150f, 110f) to listView, SizeF(250f, 110f) to gridView ) val removeViews = RemoteViews(viewMapping) appWidgetManager.updateAppWidget(appWidgetId, removeViews)
  5. 18

  6. 21 • 特別なケースを除いて、バックグラウンドからForeground Serviceを実行できなくなる ◦ ForegroundServiceStartNotAllowedException • 特別なケース ◦ Notification,

    Widgetのタップなど ◦ high-priorityのFCMメッセージ ◦ BOOT_COMPLETED、MY_PACKAGE_REPLACEDのブロードキャスト ◦ https://developer.android.com/about/versions/12/foreground-services#cases-fgs-background-starts-allowed Foreground service launch restrictions
  7. 23 val request = OneTimeWorkRequestBuilder<SampleWork>() .setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) .build() WorkManager.getInstance(context).enqueue(request) // Worker

    class SampleWork(...) : CoroutineWorker(...) { override suspend fun doWork(): Result { // ... return Result.success() } override suspend fun getForegroundInfo(): ForegroundInfo { // Android 12未満のときはForeground Service } }
  8. 29

  9. 31

  10. 33

  11. 35 Manifest merger failed : android:exported needs to be explicitly

    specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. Build error message Lint warning When using intent filters, please specify android:exported as well
  12. Kenji Abe - Android, Kotlin GDE / DeNA @STAR_ZERO Thank

    you! https://developer.android.com/about/ve rsions/12 Resources 36