한국어

Coding

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

     페북공유

   ◎위챗 : speedseoul


  
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


암묵적인 BroadcastReceivers에게 작별 인사를 할 시간입니다.
이 기사는 또한 Codemate Blog에 게시되었습니다.

Android O 개발자 미리보기가 종료되었습니다. 이제는 O가 내놓을 맛있는 디저트를 추측 할 때입니다.

모든 Android 개발자는 곧 출시 될 OS 버전의 동작 변경 목록을 확인해야합니다. 멋지게 분류되었으므로 Android O를 타겟팅하는 앱의 동작 변경 사항과 Android O를 실행하는 기기의 모든 API 수준에 영향을주는 변경 사항을 확인할 수 있습니다.

그러나 브로드 캐스트 제한 섹션을 건너 뛸 수 있습니다. 나는 당신을 덮었습니다.

tl; dr : Android O로 앱을 업데이트 할 계획이 없다면 괜찮습니다. Android O 및 그 반짝이는 새로운 기능을 타겟으로하고 AndroidManifest에 암시 적 BroadcastReceivers를 등록한 경우 계속 읽기 바랍니다.

참고 : 영향을받지 않는 방송에 대한 예외 목록이 있습니다. 따라서 앱이 예를 들어 ACTION_BOOT_COMPLETED 또는 ACTION_HEADSET_PLUG에 의존하는 경우 다른 앱과 마찬가지로 계속 정상적으로 작동합니다.

절전에 관한 모든 것
성능 및 배터리 수명을 극대화하는 것은 Android의 중요한 과제였습니다. 안드로이드 Marshmallow에서, Doze 및 App Standby는 이전의 열악한 배터리 수명을 극적으로 최적화하기 위해 도입되었으며, 이는 대부분의 최신 휴대 전화의 진정한 문제점입니다.

Doze는 특별한 유지 관리 기간에 배터리 소모 백그라운드 작업을 수행하도록 모든 앱을 제한했지만 App Standby는 가장 최근에 사용한 앱에 대한 지연된 네트워크 활동을 제공합니다. Doze와 함께 JobScheduler가 소개되었고 Google은 개발자가 모든 백그라운드 작업을 예약하는 데 사용하도록 촉구하기 시작했습니다.

배터리를 절약하는 것이 BroadcastReceivers와 어떤 관련이 있습니까?
Android Nougat을 사용하면 AndroidManifest에 3 개의 다른 암시 적 BroadcastReceivers를 등록하는 지원이 제거되었습니다.

Android O를 타겟팅하는 앱을 사용하면 매니페스트에 등록 된 모든 암시 적 BroadcastReceiver가 작동을 멈 춥니 다.

결국 앱은 불필요한 암시 적 BroadcastReceivers를 매니페스트에 등록하여 불필요한 배터리 소모를 유발했습니다. 예를 들어, 많은 앱이 CONNECTIVITY_ACTION 브로드 캐스트에 대한 수신자를 등록했습니다. "그래서"당신은 생각할지도 모릅니다. "배터리 소모와 어떤 관련이 있습니까?"

이것을 상상해보십시오. 연결 변경 이벤트를 수신하는 12 개의 앱이 있습니다. 식료품 쇼핑을 가기 위해 집을 나선다. 집에서 나가면 집에서 WiFi 연결이 끊어집니다. Android 시스템은 CONNECTIVITY_ACTION 브로드 캐스트를 전송하고 12 개의 모든 앱을 실행하여 해당 변경 사항에 반응합니다.

Wi-Fi는 더 이상 사용할 수 없기 때문에 모바일 네트워크에 연결됩니다. CONNECTIVITY_ACTION 브로드 캐스트를 다시 보냈습니다. 집에 돌아와서 Wi-Fi에 다시 연결할 때도 동일한 순서가 반복됩니다.

네트워크 연결 이벤트, 카메라를 통해 찍은 새로운 사진, 새로운 앱 설치 / 제거 이벤트, 충전기 연결 / 연결 해제 이벤트 등을들을 수있는 20 개의 앱을 상상해보십시오. Android 팀은 AndroidManifest에 등록 된 암시 적 브로드 캐스트를 제거하는 데 꽤 공정한 점을 알게됩니다.

이러한 모든 앱은 AndroidManifest에서 이러한 브로드 캐스트를 등록하기 때문에 항상 이러한 이벤트를 수신하기 위해 깨어났습니다. 포 그라운드에 있지 않거나 전혀 실행되지 않는 경우에도.

내 매니페스트에 BroadcastReceiver를 등록했습니다. 지금 무엇을해야합니까?
당황하지 마십시오. 기존 코드를 Android O와 호환되도록 마이그레이션하는 것은 실망 스럽지만 중요한 변화는 아니며 더 큰 이익을위한 것입니다.

BroadcastReceiver가 암시 적인지 또는 명시 적인지 확인
설명서에 따르면 앱과 직접 관련이없는 브로드 캐스트는 암시 적 브로드 캐스트입니다. 설명서 상태와 마찬가지로 ACTION_PACKAGE_REPLACED는 새로 설치된 모든 패키지를 알려주기 때문에 암시 적 브로드 캐스트입니다.

마찬가지로 앱과 직접 관련이있는 브로드 캐스트는 명시적인 것입니다. 따라서 ACTION_MY_PACKAGE_REPLACED는 앱만 업데이트 될 때 알려주기 때문에 명시적인 브로드 캐스트입니다.

들을 수있는 대부분의 방송은 암시적인 방송입니다.

앱이 영향을 받는지 확인하십시오.
Android 개발자 설명서는 영향을받지 않고 계속 정상적으로 작동하는 암시 적 브로드 캐스트의 목록을 제공합니다. 즉, 앱이 AndroidManifest에서 이러한 암시 적 브로드 캐스트에 대한 수신기 만 등록하고 이러한 경우에만 안전합니다.

영향을받지 않는 가장 일반적인 것들은 블루투스 상태 변경을위한 ACTION_BOOT_COMPLETED, ACTION_HEADSET_PLUG 및 ACTION_CONNECTION_STATE_CHANGED이며 다른 많은 것들도 마찬가지입니다.

구조 대원 JobScheduler
네트워크 연결, 충전기 또는 장치 유휴 이벤트를 청취했다면 대신 작업에 JobScheduler를 사용하고 싶을 것입니다.


JobScheduler는 안드로이드 시스템과 Doze 배터리 최적화를 잘 수행합니다. 정의 할 수있는 조건에 따라 태스크를 실행할 수 있습니다. 예를 들어 대기 모드에서 충전기가 연결되고 장치가 작동중인 네트워크 연결을 가지고 있으면 작업이 실행되도록 예약 할 수 있습니다.

It’s time to kiss goodbye to your implicit BroadcastReceivers

This article was also posted on Codemate Blog.

Android O Developer Preview is out! It’s time to start guessing what delicious dessert the letter O will stand for.

Every Android developer should check the list of behavior changes in the upcoming OS version right now. It’s nicely sectioned, so you see the behavior changes for only apps that target Android O, and changes that affect every API level on devices running Android O.

But you can skip the Broadcast Limitations section. I’ve got you covered.

The tl;dr: if you aren’t planning to update your app to Android O, you’re fine. But if you want to target Android O and its shiny new features AND you have registered implicit BroadcastReceivers in your AndroidManifest, keep on reading.

NOTE: There’s a list of exceptions for broadcasts that aren’t affected. So if your app relies, for example, on ACTION_BOOT_COMPLETED or ACTION_HEADSET_PLUG, with many others, they’ll continue to work normally.

It’s all about saving power

Maximizing performance & battery life has been a big priority for Android for a while. In Android Marshmallow, Doze and App Standby were introduced to dramatically optimize previously poor battery life, a real pain point of most modern mobile phones.

While Doze restricted all apps to do battery-consuming background tasks in special maintenance windows, App Standby deferred network activities for least recently used apps. Along with Doze the JobScheduler was introduced, and Google began to urge developers to use it to schedule all background tasks.

What does saving battery have to do with BroadcastReceivers?

With Android Nougat, the support for registering three different implicit BroadcastReceivers in your AndroidManifest was removed.

With apps targeting Android O, all implicit BroadcastReceivers registered in the manifest (except these) will stop working.

As it turns out, apps were registering a lot of unnecessary implicit BroadcastReceivers in their manifest, causing unwanted battery drain. For example, a lot of apps registered receivers for the CONNECTIVITY_ACTION broadcast. “So what”, you might think. “What does that have to do with battery consumption?”

Imagine this: you have dozen apps that listen for connectivity change events. You leave home to go grocery shopping. The connection for the home wifi drops once you exit your apartment. Android system sends the CONNECTIVITY_ACTION broadcast, and causes all of those dozen apps to wake up and react to that change.

Since the wifi is no longer available, you get connected to the mobile network. Guess what, the CONNECTIVITY_ACTION broadcast gets sent again. The same sequence happens again when you get back home and reconnect to your wifi.

Imagine 20 apps that each listen for network connection events, new pictures taken through camera, new app installed / uninstalled events, charger connected / disconnected events… You quickly realize the Android Team has a pretty fair point in eliminating implicit Broadcasts registered in the AndroidManifest.

Since all those apps register for these broadcasts in their AndroidManifest, they’re always woken up to receive these events. Even when they’re not in the foreground or even running at all.

I have registered a BroadcastReceiver in my manifest, what now?

Don’t panic. Remember that while it may be frustrating to migrate your existing code to be Android O compatible, it’s not a major change and it’s all for the greater good.

Determine if the BroadcastReceiver is implicit or explicit

According to the documentation, any Broadcast that’s not directly related to your app is an implicit Broadcast. Like the documentation states, ACTION_PACKAGE_REPLACED is an implicit broadcast, since it notifies you of every newly installed package.

Likewise, any Broadcast that’s directly related to your app is an explicit one. So ACTION_MY_PACKAGE_REPLACED is an explicit Broadcast, since it notifies you when only your app is updated.

Most of the Broadcasts you can listen to are implicit ones.

Check if your app is affected

Android Developer documentation provides a list of implicit Broadcasts that aren’t affected and will continue to work normally. That means if your app only registers listeners for these implicit Broadcasts in the AndroidManifest, and these only, you’re safe.

The most common unaffected ones are ACTION_BOOT_COMPLETEDACTION_HEADSET_PLUG and ACTION_CONNECTION_STATE_CHANGED for Bluetooth state changes, with many others.

JobScheduler to the rescue

If you listened for network connection, charger or device idle events, the chances are you want to use JobScheduler for your task instead.

JobScheduler plays nicely with the Android system and Doze battery optimizations. It allows executing tasks based on conditions that you can define. For example, you can schedule a Job to be executed once the charger gets connected and the device has a working network connection while being in idle mode.

JobScheduler is only supported on Android Lollipop (API 21) and up. If your app has a minSdkVersion below 21, there’s libraries with similar APIs that provide backwards compatibility. The officially recommended one is FirebaseJobDispatcher.

We at Codemate are currently having great success with Evernote’s Android-Job library. Android-Job uses JobScheduler on devices that have Lollipop or greater and falls back to GCMNetworkManager or AlarmManager depending on if the system has Google Play Services installed or not.

Context.registerReceiver() has always got your back

Whether your Broadcast is implicit or explicit, you can always register it by using the Context.registerReceiver() method inside your Activity, Service, Fragment or even a custom View.

So, for example if your AndroidManifest had a receiver for listening charger events:

You would remove that receiver from your AndroidManifest.xml and the BatteryReceiver class completely, and move listening logic inside your Activity, Service, Fragment, whatever:

The difference of registering BroadcastReceivers with Context.registerReceiver() is that you must eventually also unregister it, while receivers defined in you manifest will wake up your app no matter what. When to unregister depends on where you first register your receiver.

If done inside an Activity / Fragment, a good place to unregister is the onDestroy callback. Inside a Service, unregister when you don’t need to receive those events any more.

Conclusion

Get rid of all implicit (except these) BroadcastReceivers in your AndroidManifest. Use JobScheduler, FirebaseJobDispatcher or alternatives for your tasks instead. If those don’t support the event you were listening to, register BroadcastReceivers in your Activity, Service, Fragment or View depending on your needs.


I’m a mobile developer happily working at Codemate. If your company needs a mobile app or a website, contact us. We’ve got you covered.

조회 수 5362
조회 수 5269
FCM 푸시 메세지 전송
admin
2019.09.27
조회 수 5621
조회 수 7414
조회 수 7977
조회 수 6388
조회 수 7222
조회 수 7755
조회 수 7289
조회 수 11175
조회 수 6672
조회 수 7773
조회 수 7060
조회 수 6902
android apk 패키징 v1, v2
admin
2018.12.05
조회 수 7443
조회 수 7151
조회 수 6910
조회 수 7040
조회 수 7981
SDK Platform Release Notes
admin
2018.05.13
조회 수 7343
sdk-tools list
admin
2018.05.13
조회 수 7343
조회 수 7810
조회 수 7732
조회 수 7239
조회 수 7384
Firebase용 Cloud 함수
admin
2018.04.26
조회 수 7751
안드로이드 알람
admin
2018.02.23
조회 수 7925
조회 수 7876
조회 수 7813
gcm 코딩 사례
admin
2018.01.09
조회 수 7687
조회 수 12388
조회 수 8086
조회 수 8741
조회 수 8133
조회 수 10196
FCM PHP Curld
admin
2018.01.01
조회 수 8661
FCM 과 GCM 차이
admin
2018.01.01
조회 수 10271
조회 수 8014