Badoo Arkady Gamza Jun 8, 2017

Reactive Camera Implementation with Camera2 API on Android - Part 1

Article Summary

Arkady Gamza from Bumble Tech tackles Android's notoriously complex Camera2 API by wrapping it in RxJava2 observables. The result? A reactive camera implementation that turns callback hell into elegant, readable code.

This deep technical dive shows how to build a fully functional camera app using Camera2 API with RxJava2 for async control flow. Gamza walks through every step from device selection to photo capture, demonstrating how reactive programming tames Android's callback-heavy camera interface.

Key Takeaways

Critical Insight

RxJava2 transforms Camera2 API's async complexity into clean, maintainable operator chains that handle device lifecycle, preview streaming, and photo capture without callback nesting.

Part 2 reveals the implementation details for autofocus waiting, automatic exposure selection, and orientation handling that complete the production-ready camera.

About This Article

Problem

Camera2 API uses asynchronous callbacks that nest deeply when you need to coordinate multiple device lifecycle events. Opening the camera, creating a session, and starting preview streaming all require managing complex callback chains that are hard to follow and maintain.

Solution

Arkady Gamza converted Camera2's callback methods into RxJava2 Observables using Observable.create() and PublishSubject. The StateCallback and CaptureCallback interfaces became reactive streams that emit DeviceStateEvents and CaptureSessionData objects.

Impact

The reactive approach flattened the preview initialization chain. Instead of nested callbacks, developers write a single readable sequence using flatMap and filter operators. Coordinating autofocus, autoexposure, and photo capture no longer requires callback nesting or manual thread management.