简体   繁体   中英

Android SurfaceView Thread with multiple activities

I have a thread as part of a surface view object:

public class GameArena extends SurfaceView implements SurfaceHolder.Callback
{
      private GameThread thread = null;
      // Etc
}

And this surface view is part of an activity.

Later when the user clicks the screen, a new activity is launched, with its own different surface view.

The problem I have is finding how/when to cancel this thread when the user press' the home button in the second activity, as when they start the app again the thread already exists.

Many Thanks

You should not have the Thread created within the SurfaceView, instead you should create the thread within an activity that owns the surfaceView. In addition, synchronization is needed between the Thread and Activity thread the life cycle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM