Nosmai  Effects Nosmai  Moderation Nosmai Try-ons coming soon
Docs menu Android
How-to guide

Manage the camera lifecycle on Android

Coordinate the host-owned Camera2 session with Nosmai processing so pause, lens switching, navigation, and cleanup keep one camera owner.

Platform Android SDK version 3.0.4 Updated Aug 22, 2026 Time 7 min

Prerequisites

  • A working Android quickstart
  • One host-owned Camera2 helper connected to NosmaiPreviewView
  • A serialized camera open, close, and lens-selection state machine

Pause and resume the screen

The Android native SDK processes frames; the host application owns Camera2. Close the repeating request and camera device before pausing the preview:

@Override
protected void onPause() {
    camera2Source.close();
    previewView.onPause();
    super.onPause();
}

On resume, wait for the preview's OES surface callback and open the selected camera against that current SurfaceTexture. Do not reuse a surface from a destroyed view.

Switch the camera

Stop the current capture session, close its device, select the other Camera2 ID, and reopen only after close completion. Keep the switch control disabled during that transition. The host Camera2 helper—not NosmaiSDK—owns this lens selection in the native Android integration.

Release processing

Close Camera2 before stopping the processing pipeline:

camera2Source.close();
NosmaiSDK.stopProcessing();

Do not call NosmaiSDK.cleanup() for every configuration change. Use global cleanup only when the process no longer needs the initialized SDK state.

Verify it worked

Switch lenses repeatedly, background and foreground the activity, then reopen the screen ten times. Each transition must keep one Camera2 device open and the camera indicator must turn off after leaving.

Common errors

SymptomCauseFix
Camera device error: 2Another session still owns the selected deviceAwait Camera2 close before opening the Nosmai screen or other lens
Preview freezes after switchingThe new session targets an old OES surfaceReopen against the current preview callback surface
Camera opens twice after resumeActivity and preview callbacks both start the sourceMake one state machine the only Camera2 owner

Next steps

References

Was this page helpful?

Your response helps us prioritize documentation improvements.

Nosmai

An AR and AI company. Founded on the idea that the next decade of software will be visual, and that the tools for it should be within reach of anyone building.

Newsletter

Product updates and release notes. No spam.

© 2026 nosmai, inc · all rights reserved