8

I have a TextureView in my code to which I've set a SurfaceTextureListener.

On Android 6.0 the methods onSurfaceTextureDestroyed and onSurfaceTextureAvailable are called whenever I leave the activity and return (respectively) while on Android 7.0 I notice that onSurfaceTextureAvailable is only called once after the Activity is created.

The surface is not destroyed and recreated whenever I leave the activity and return like I'm used to from Android 6.0.

After some investigation I notice that API 18,19,24 behave one way and API 20-23 behave the other way.

Any idea why, and mainly how to make it behave the same on all Android versions?

Hadas Kaminsky
  • 1,285
  • 1
  • 16
  • 39
  • where you want call this method(onSurfaceTextureDestroyed)? – Muhammad Waleed Apr 28 '17 at 02:55
  • Not sure I understand your question @Javacoder, I expected the method to be called each time I leave the activity, meaning whenever onPause is called. This is the behavior on Android 6.0. – Hadas Kaminsky May 02 '17 at 15:57
  • 1
    Might be an optimization, similar to the way SurfaceView behaves... does it change depending on whether you leave the app or lock the screen? cf. https://source.android.com/devices/graphics/arch-sv-glsv#activity – fadden May 09 '17 at 16:33
  • Thanks @fadden for your comment and for the link. The difference is actually in when in the lifecycle the methods are fired. So on Android 6.0 onSurfaceTextureDestroyed is called after onPause and before onStop, but on Android 7.0 it is called only after onStop and only if onDestroy is called. So if the Activity is not destroyed and recreated but only stops and starts the methods are not called. This is a big difference when trying to implement for both APIs. – Hadas Kaminsky May 09 '17 at 16:48
  • why not intercept the standard life cycle methods then – Remario May 12 '17 at 00:39
  • 1
    @Remario, this is tricky - if I do not detach a surface on or before onSurfaceTextureDestroyed, I get SurfaceTexture errors 'BufferQueue has been abandoned' so I must do it before. In addition if I attach surface before onSurfaceTextureAvailable I might not have it yet. It gets complicated because I move between activities that contain a surface each (for the same video stream) so I need to detach and attach on time, so the order in which the methods are called is critical, I basically need different implementations and I can't even say according to what? according to API? – Hadas Kaminsky May 12 '17 at 01:10
  • I was facing same problem with TextureView, It behave very strange in Android 7 and up, in my case it was working good in tablet but not in mobile(Android 7). To solve this, I replaced TextureView by SurfaceView and that works fine in all Android version. – Anand Singh May 12 '17 at 10:37
  • @AnandSingh Unfortunately SurfaceView is not suitable for my needs, but it's interesting to know that the tablet behaves differently, are you saying that the tablet is also Android 7.0 but doesn't have the 'strange behavior' that other Android 7.0 devices have? – Hadas Kaminsky May 24 '17 at 16:47
  • 1
    Yes, In tablet it was working fine but in Mobile device it wasn't. Both having android 7 – Anand Singh May 24 '17 at 17:31
  • Thanks @AnandSingh, this is important info, it means that it's not a good practice to distinguish according to Android version. – Hadas Kaminsky May 24 '17 at 17:56
  • did you find a solution? same problem here https://stackoverflow.com/questions/52497074/onsurfacetexturedestroyed-isnt-called-in-android-7-8-surfacetexture-setdefault – user924 Sep 25 '18 at 11:35

1 Answers1

-1

I was facing the same, but i solve the issue by adding below in Manifest

android:hardwareAccelerated="true"
sharma_kunal
  • 2,152
  • 1
  • 28
  • 28
  • when you work with SurfaceTexture, you are supposed to have it already, so I had it already and issue still happened, so your answer doesn't make sense – user924 Sep 25 '18 at 11:37
  • By default this is already set true. The only use for this command is to set it to false. – Marc Alexander May 03 '19 at 19:17