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?
Asked
Active
Viewed 2.6k times
11

MByD
- 135,866
- 28
- 264
- 277

Hani Honey
- 2,101
- 11
- 48
- 76
-
I can trigger it by changing the phone's orientation from portrait -> landscape for example. – Bruno Bieri Apr 16 '20 at 13:27
2 Answers
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
-
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
-
1You 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