First of all, a very grateful thanks for creating this wonderful implementation. Since we use Cocos2D for iOS, it was a very obvious choice to use Cocos2D-x for Android.
We worked with the code migration from Objective C to C++ and it was very smooth … except for one irritation.
Problem: The problem that we face now is that on an Android device, the application will not quit (application does not end, it does not close but instead it keeps running) when the Home button is pressed. It happens on an Android tablet 2.2. There is only one button - the Home button. I have to reboot the tablet to end the application.
Even keeping an “x” image button (as given in HelloWorld program) inside the program screen (which calls sharedDirector::end() ) does not respond till touched 10 to 15 times, over 10 seconds. This can become an irritation for end users.
On an Android 2.3 phone, the app does not respond to a back button, Home button works by sending it to background. Back button works for quitting other apps but not Cocos2d-x app.
Cocos2d-x version is 1.0.1-x-0.9.1. We used templates etc supplied with that zip.
Any inputs would be helpful. Where should I look or make changes ?
Something like changelist 626 (http://www.cocos2d-x.org/issues/626) could be of use in this case, but that was for Marmalade. This problem we have is for Android.
Can you tell the exact name of “an android table 2.2” & “an Android 2.3 phone”, e.g. moto xxxx or samsung ixxx
Does it happen on all your android devices?
The Android Tablet is a Barnes and Noble “Nook Color” with Android 2.2. Home button does not work in a Cocos2d-x app. It works for all other apps.
The Android Phone is a Samsung Galaxy Pop S5570 with Android 2.3. Home button works, but Back button does not work in a Cocos2d-x app. Home and Back buttons work well for all other apps.
I am experiencing the same think with the Nook tablet. No back button, obviously, but pressing the home button has no effect. If I press it twice it will break out of the app but the normal behavior for a Nook app is that a single push of the home button will overlay the device’s menu. My code is a very slightly modified version of HelloWorld.
Thanks for all your hard work, it has been a steep learning curve but I now have my code running in Windows, Linux, and the Nook. Going to try and get iOS working tomorrow but very encouraged by the results thus far.
Thanks for your reply. B&N complains that clicking on the home button does not exit the app. I tried, when I double click the home button, the app exit. But the single click on home button, the app does not exit.
As I know, Android doesn’t terminate a program by pressing Home Menu.
You should do more thing to listen Home Menu touching event, should declare something in AndoridManifest.xml and write corresponding call back function.
I haven’t done it.
You can search solution by google.
I’ve come across this same issue as well, and it will certainly fail the B&N app submission standards.
In Marmalade, the framework actually captures the Nook home key event as an abstract back softkey, as s3eKeyAbsBSK. Normally you wouldn’t want to capture a home key event but the Nook is a special case, as the app will not take any action at all if the home key is pressed only once and we need it to suspend the app. I’ve tried overriding OnBackPressed and OnUserLeaveHint on the Java side, but that did not work.
Is there anything similar in Cocos2dx for Android? I don’t see any other way for an application to listen to the home key event without the framework supporting it.
Edit: Messing around a bit on the C++ side, Milda Genius’ solution worked!
My MainMenu inherits from cocos2d::CCLayer
I added a virtual void keyBackClicked(); in MainMenu.h
Then in MainMenu.cpp I added this->setIsKeypadEnabled(true); in MainMenu::init() and added a method:
void MainMenu::keyBackClicked() {
CCDirector::sharedDirector()->end();
}
And it worked. Wish there was an easier way but I’ll just have to add this to every layer.
Hello guys , i put this code in my project , its ok now!
Another question is about background app crash after some time , every time i press home button and my app goes to background after 30 minutes more or less , its appear " Activity XXX , dos not respond"
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->resume();
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
GameManager::sharedGameManager()->getLevelAtual()->applicationWillEnterForeground = true;
}
This does not work in my appp. The function callback is not triggered. I put a CCLog call to check and it does not get hit. Any reason why this is happening?
I am creating an application using cocos2d-x 2.0.4 in xcode5. It is a timer application for particular time it is creating sounds. It is working fine. But when i lock my device the application goes to pause, and while unlock it resumes and start running from where it pause. So i want to know whether is it possible to make my application run on background. I convert this and using it for android. So please help me solve this. thanks.