Android Question [SOLVED] SurfaceView in background service

KZero

Active Member
Licensed User
Longtime User
Hi,

i'm using LibStreaming to stream video to RTSP server, i use SurfaceView to preview the video

the Surfaceview in a Service and i adding it to the activity (activity.addview)

if the activity paused the surfaceview destroys and stream stop

is it possible to sync the preview from the off-screen surfaceview created in the services to other surfaceview or even imageview in the activity ? or any other way to show the preview in the activity probably without destroying the main surfaceview if the activity paused

thanks
 

DonManfred

Expert
Licensed User
Longtime User
I guess the answer is no.
The Camera (and it´s preview in a SurfaceView) needs an ACTIVITY to work on. You can not add a surface to the service. The service does not have a activity-context so the camera can not work in a service.
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User
I guess the answer is no.
The Camera (and it´s preview in a SurfaceView) needs an ACTIVITY to work on. You can not add a surface to the service. The service does not have a activity-context so the camera can not work in a service.
it already working off screen in the background service, the problem is how to preview the running Surfaceview on the activity without destroying it when the activity paused
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Don't add it to the activity.

For this you will need to add it somewhere else. Create a viewgroup in the same service and add it to the windowmanager. Your surfaceview will be working independently of the activity lifecycle.

If you want to "link" its behaviour to the activity, you can use the activity events to know when to show it if activity is running (as if it was inserted in the activity), and hide it on activity pause (if this is the effect you want to achieve)

I have something similar also working with the camera when screen is off, but stopped due to lack of time https://www.b4x.com/android/forum/threads/having-fun.62566/
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User

done , thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…