[Android] EventBus

EventBus is a publish/subscribe event bus optimized for Android.EventBus-Publish-Subscribe

EventBus…

  • simplifies the communication between components
    • decouples event senders and receivers
    • performs well with Activities, Fragments, and background threads
    • avoids complex and error-prone dependencies and life cycle issues
  • makes your code simpler
  • is fast
  • is tiny (~50k jar)
  • is proven in practice by apps with 100,000,000+ installs
  • has advanced features like delivery threads, subscriber priorities, etc.

 

EventBus in 3 steps

  1. Define events:
  2. Prepare subscribers: Register your subscriber (in your onCreate or in a constructor):
  3. Declare your subscribing method:
  4. Post events:

Gradle:

 

License

Copyright (C) 2012-2016 Markus Junginger, greenrobot (http://greenrobot.org)

EventBus binaries and source code can be used according to the Apache License, Version 2.0.

[Android] Notification 설정

알림 작업

선택 항목이기는 하지만 알림에 작업을 하나 이상 추가해야 합니다. 작업은 사용자가 알림에서 애플리케이션의 Activity로 바로 갈 수 있게 하고, 여기에서 사용자는 하나 이상의 이벤트를 보거나 더 많은 작업을 할 수 있습니다.

하나의 알림은 여러 개의 작업을 제공할 수 있습니다. 사용자가 알림을 클릭했을 때 트리거되는 작업을 항상 정의해야 합니다. 일반적으로 작업은 애플리케이션의 Activity를 엽니다. 또한, 알람 다시 알림이나 텍스트 메시지에 즉시 답장 등과 같은 추가 작업을 수행하는 알림 버튼을 추가할 수 있습니다. 이 기능은 Android 4.1부터 사용할 수 있습니다. 추가 작업 버튼을 사용할 경우, 앱의 Activity에서 해당 기능을 사용할 수 있게 해야 합니다. 자세한 정보는 처리 호환성 섹션을 참조하십시오.

Notification에서 작업 자체는 애플리케이션에서 Activity를 시작하는 Intent가 포함된 PendingIntent가 정의합니다. PendingIntent를 동작과 연관시키려면NotificationCompat.Builder의 적절한 메서드를 호출합니다. 예를 들어, 사용자가 알림 창의 알림 텍스트를 클릭했을 때 Activity를 시작하려면,setContentIntent()를 호출하여 PendingIntent를 추가합니다.

사용자가 알림을 클릭했을 때 Activity를 시작하는 동작이 가장 보편적인 작업 시나리오입니다. 또한, 사용자가 알림을 무시했을 때 Activity를 시작할 수도 있습니다. Android 4.1 이후부터는 Activity를 작업 버튼에서 시작할 수 있습니다.