Start activity from Facebook issue

Start activity from Facebook issue
0.0 0


I am having problems when resuming/starting my app through the Android Facebook app (app request, link etc).

If I start my app by clicking on it’s icon, it will launch correctly. If I then minimize the app, open Facebook and click on an app request, it will start a new activity and call “onCreate” again on my main class.

If I do it the other way around, start the app through Facebook, minimize and resume by clicking on my app icon, the same thing will happen.

Is this normal behavior? It doesn’t crash my app but it causes all sound to be lost and instead of exiting the app restarts when “CCDirector::sharedDirector()->end()” is called.


This is a bug in “CCDirector::sharedDirector()->end()”.
It kills the processes instead of finishing the activity.
Anyway, what do you need to “CCDirector::sharedDirector()->end()”?


Isn’t CCDirector::sharedDirector()->end() the correct way to exit an application on user click? Basically just took it from the tests.

Managed to get the sound issue fixed by changing the sound/music setup in Cocos2dxActivity to:

// init media player and sound player
if(backgroundMusicPlayer != null) backgroundMusicPlayer.mContext = this;
else backgroundMusicPlayer = new Cocos2dxMusic(this);

if(soundPlayer != null) soundPlayer.mContext = this;
else soundPlayer = new Cocos2dxSound(this);

Not sure if it will cause any problems, but everything except the exit issue seems to be working properly.


Been testing for awhile now and the edits in code for sound seem to be working, in case someone else has the same problem.

The restart issue is still there though. Is “CCDirector::sharedDirector()->end()” the correct way to exit a cocos2d-x application or are there any other options? Thanks


Ok, so I managed to get the restart bug fixed and my app closes correctly when exiting from button click. Thing is I’m not sure if there are any negative implications when handling it this way. Basically all I did was add a static instance variable to my Main activity’s onCreate() method, and finish the old activity when this is called.

if(me = this) {
me = null;

me = this;

Anyone know if that’s a bad way to handle it? Thanks =)