11

I'm having trouble figuring out when surfaceDestroyed() occurs. I am trying to make my threads stop running in the surfaceDestroyed() method (of a SurfaceView) but it appears that my surface is never actually destroyed...can someone tell me when this happens? Or how to trigger it?

MByD
  • 135,866
  • 28
  • 264
  • 277
Hani Honey
  • 2,101
  • 11
  • 48
  • 76

2 Answers2

23

Whenever you click return or home button and leave the activity you get:

Activity onPause

surfaceDestroyed

and finally activity onDestroyed.

When you return the surfaceView is recreated, however if you have been using static variables do drive the application, they will be often preserved and it may only seem like surfaceView was not destroyed.

Regarding closing the thread, check this: Android crash when app is closed and reopened

Community
  • 1
  • 1
Lumis
  • 21,517
  • 8
  • 63
  • 67
  • See, I thought it was whenever you returned. However, I try to stop my threads in the SurfaceDestroyed method.....but they keep running @.@ – Hani Honey Apr 09 '11 at 23:16
  • 1
    You cannot easily stop threads, just stop the loop in them and then use JOIN so that they finish on their own and "join" the main UI thread and then you can close the UI thread properly. See surfaceDestroyed method in the question code of the link I provided. – Lumis Apr 10 '11 at 00:22
2

surfaceDestroyed() is not called when the view is managed by a TabHost.

l33t
  • 18,692
  • 16
  • 103
  • 180