It is tooooo slow swith between cocos2d-x activity and android activity

I have a main activity which is extends cocos2dActivity(here I refer it as A), and another activity(here I refer it as B)
at sometimes I need to switch A to B, after B finished, jump back to A

in A:

Intente intent= new Intent(A.class,B.java)
startActivityForResult(intent)

in B:
do sth…
finish();

but when jump back from B to A, it’ll speed a long time even more than 5 second.

any idea??

thanks

anyone?
any idea?

it takes time to reload all textures you have load before…
so reduce the texture you use then it should be decrease the time when resume.

is there any way to keep all current activity’s texture to switch to another activity? so when I back to first activity there is no need for me to reload that?

thanks,all.
i think I got what I need.
thanks again.

Im having same problem when my app when I press home button and then try to come back. Someone reach a solution?

Sorry to say it but there’s no solution (that will work on all android versions). Read up on why in the link I posted above.

If you only support devices > Honeycomb, you can set a function setPreserveEGLContextOnPause. On older Android versions, you have to implement a hack (explained in the link).

Again, even with the solution/hack, android can and will clear the context if it needs the memory and it will again be slow when you come back to your game.

Ro Siade wrote:

Im having same problem when my app when I press home button and then try to come back. Someone reach a solution?

Thanks for your answer. I’m having problems with found answers on your link, the GLSurfaceView I found was very different from the one people talking, and this http://code.google.com/p/replicaisland/source/browse/trunk/src/com/replica/replicaisland/GLSurfaceView.java I was unable to use without errors.

If you can give me some more little help all the community will be thankfully!

PS: I test the setPreserveEGLContextOnPause on the initView of Cocos2dxGLSurfaceView and work nice on my galaxy nexus except when I press the power button, the game take a lot to come back, any idea :)?.

Irwin Billing wrote:

Sorry to say it but there’s no solution (that will work on all android versions). Read up on why in the link I posted above.
>
If you only support devices > Honeycomb, you can set a function setPreserveEGLContextOnPause. On older Android versions, you have to implement a hack (explained in the link).
>
Again, even with the solution/hack, android can and will clear the context if it needs the memory and it will again be slow when you come back to your game.
>
Ro Siade wrote:
> Im having same problem when my app when I press home button and then try to come back. Someone reach a solution?

Right. The implementation from replica island is really old. I wouldn’t recommend using that.

May I suggest a compromise? There is no real solution to get this to work that will be stable on all devices. The hack can break on certain hardware.
Check if you’re running on > Honeycomb, use that method, otherwise don’t do anything.

You just have to make sure that there isn’t much to load when you resume to make the loading faster.
You may do this by optimizing your textures and,
for example, inside applicationDidEnterForeground, remove all unused sprite frames and textures, reducing the number of textures to re-load.

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
        /* The relevant part. */
    CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames();
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
        /* The relevant part. */

    CCDirector::sharedDirector()->pause();

    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

Also, don’t forget to reloadAllTextures() on resuming.

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
        /* The relevant part. */
    CCTextureCache::sharedTextureCache()->reloadAllTextures();
        /* The relevant part. */

    CCDirector::sharedDirector()->resume();

    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

Irwin Billing wrote:

Right. The implementation from replica island is really old. I wouldn’t recommend using that.
>
May I suggest a compromise? There is no real solution to get this to work that will be stable on all devices. The hack can break on certain hardware.
Check if you’re running on > Honeycomb, use that method, otherwise don’t do anything.
>
You just have to make sure that there isn’t much to load when you resume to make the loading faster.
You may do this by optimizing your textures and,
for example, inside applicationDidEnterForeground, remove all unused sprite frames and textures, reducing the number of textures to re-load.
>
[…]
>
Also, don’t forget to reloadAllTextures() on resuming.
>
[…]

Unfortunately I have many animations to load and already does a big optimization reducing sizes, frames, etc. Did you lost EGLContext even after put the setPreserveEGLContext(true) when you put your phone to sleep??

Regards

Ro Siade wrote:

Irwin Billing wrote:
> Right. The implementation from replica island is really old. I wouldn’t recommend using that.
>
> May I suggest a compromise? There is no real solution to get this to work that will be stable on all devices. The hack can break on certain hardware.
> Check if you’re running on > Honeycomb, use that method, otherwise don’t do anything.
>
> You just have to make sure that there isn’t much to load when you resume to make the loading faster.
> You may do this by optimizing your textures and,
> for example, inside applicationDidEnterForeground, remove all unused sprite frames and textures, reducing the number of textures to re-load.
>
> […]
>
> Also, don’t forget to reloadAllTextures() on resuming.
>
> […]
>
Unfortunately I have many animations to load and already does a big optimization reducing sizes, frames, etc. Did you lost EGLContext even after put the setPreserveEGLContext(true) when you put your phone to sleep??
>
Regards

I have same issue, many animations, textures,…
Anyone solved this problem?

Reviving this topic since this problem still exist in 3.2.

The problem is that in platform/android/javaactivity.cpp :
Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(…) calls cocos2d::VolatileTextureMgr::reloadAllTextures();

This behavior is fine for small applications. But for big applications you want to override this behavior to implement a loading screen or something similar.

I made a basic implementation of an overridable texture reload behavior there : https://github.com/asmodehn/cocos2d-x/commit/05788a8d6f536c7817e8b2bccd2eb640b32c1b3d#diff-a6492563a758c0e34f0c8d7facf7fd78

Hope it helps. Cheers