Question

I am creating live wallpaper on LibGDX. I am using the latest version(December 2013) of it. I need to dispose some images when live wallpaper is closing or is on pause. I am using following class:

public class GdxBase implements ApplicationListener, AndroidWallpaperListener, InputProcessorLW{

public abstract boolean needsGL20();

public void create() {
//works
};

public void resume() {
    Gdx.app.log("LibGDX", "resume");//works
};

public void render() {
//works
};

public void resize(int width, int height) { 
//works
};

public void pause() {
    Gdx.app.log("LibGDX", "pause"); //never called
};

public void dispose() {
    Gdx.app.log("LibGDX", "dispose"); //never called
};
}

So when I close my live wallpaper dispose or pause are never called. I see only resume and not mine WallpaperService: engine paused records in LogCat. How to invoke them? What do I wrong?

Possible duplicate: pause and dispose() not getting called in ApplicationListener in libgdx

Was it helpful?

Solution

I know that it's an old question, but you may use this little hack in a class that extends AndroidLiveWallpaperService and catch wallpaper engine events:

@Override
public Engine onCreateEngine() {
    return new AndroidWallpaperEngine() {
        @Override
        public void onPause() {
            super.onPause();
            Log.i(TAG, "Pause!");
        }
    };
}

OTHER TIPS

In case of LiveWallpapers, the pause() and dispose() methods aren't called:

See this http://code.google.com/p/libgdx/issues/detail?id=1348

And it seems thats something that won't be fixed.

I extended the solution proposed by Odysseus.

public class LibGDXWallpaperService extends AndroidLiveWallpaperService {

public class MyLibGDXWallpaperEngine extends AndroidWallpaperEngine {
    @Override
    public void onDestroy() {           
        super.onDestroy();
        engine.dispose();
    }

    @Override
    public void onPause() {             
        super.onPause();    
        engine.pause();
    }           
}

EngineCore engine;

@Override
public Engine onCreateEngine() {        
    return new MyLibGDXWallpaperEngine();       
}

@Override
public void onCreateApplication() {
    engine = new EngineCore();  
    initialize(engine, false);
    super.onCreateApplication();
}

}

Where engine inherited from GdxBase described in question

public class EngineCore extends GdxBase {
    @Override
    public void pause() {
       Gdx.app.log("PAUSE", "PAUSE");       
    }

    @Override
    public void dispose() {
       Gdx.app.log("DISPOSE", "DISPOSE");       
    };
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top