• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How can I save a surface view drawing when going to a new activity view?

Akomada

Lurker
Apr 8, 2016
1
0
Basically, I have a gameView class, which extends Surfaceview, it has a surfaceCreated method, which runs a thread and draws stuff onto a canvas.

This gameView gets loaded from a GameActivity, with setContentView(gameView).

On the gameView, I have a touch event, so that when you touch the screen you get navigated to another activity xml layout. Basically, when you touch the canvas drawing another screen pops up.

On this new, intermediate screen I have a button which when you click it, it takes you back to the gameView.

My problem is that when it takes you back to the gameView, the canvas drawing has been reset, it seems that the surfaceCreated method is called each time with setContentView(gameView).

So my question is how can I save the gameView, its state and its canvas drawing, so that when I navigate to another activity but come back and load the gameView again, the state will still be there, and it will redraw what it had?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones