I just got started today developing for Android. I tried to make an application that uses a SurfaceView to draw some simple shapes, but couldn't get it working based on menu events (the surface was always invalid), so I decided to implement threads. Now the problem is I can't figure out how to stop a stray thread from running. I started the application in debug mode, then selected the menu item that starts the thread. Then I hit the back button on the emulator's interface to get out of the application. But my breakpoints on the thread continued to be hit. So I went back into the application by clicking on it in the application list in the emulator, and selected the command to stop the thread. But it did not detect that the thread was running -- like it was a different application instance.
There are many subtle questions underneath my main question which is "How should I handle the shut-down of threads in an android application most reliably?"
- Can I access the original instance?
- Should I have gotten the original instance when I went back in?
- Does selecting it from the application menu instead of starting the debugger affect the original instance visibility?
- Can/should I terminate the activity/application?
- Can the debugger (Eclipse) force it to stop somehow without resetting the whole device?
- Does a SurfaceView need threads in order to function rather than trying to lock the context during a menu event?
I looked at Close application and launch home screen on Android but it suggests that applications should not be terminated, so I'm not sure what to do.