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
| Symptom | Cause | Fix |
|---|---|---|
Camera device error: 2 | Another session still owns the selected device | Await Camera2 close before opening the Nosmai screen or other lens |
| Preview freezes after switching | The new session targets an old OES surface | Reopen against the current preview callback surface |
| Camera opens twice after resume | Activity and preview callbacks both start the source | Make one state machine the only Camera2 owner |