How to open cocos activity by clicking on an android notification

Hi, I’m trying to integrate cocos with android but I’m having a problem when I need to open cocos activity by clicking in a android notification on notification bar.

For my cocos activty I have this:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cocos2dxHelper.init(this, this);
setContentView(R.layout.main);
this.mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.game_gl_surfaceview);
this.mGLView.setEGLContextClientVersion(2);
this.mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
}

static {
System.loadLibrary(“game”);
}

When I start my application this code runs ok. After initialization I put my application on backgroung and run a code to receive a notification linked to this activity. When I click on the notification a black screen appears and logCat get a lot of exceptions like this:

07-26 11:33:36.826: W/Adreno200-ES20(12221): <*load_uniform_matrix:801>: GL_INVALID_OPERATION
07-26 11:33:36.826: D/cocos2d-x debug info: OpenGL error 0x0502 in C:/dev/cocos2d-x/game/proj.android/…/…/cocos2dx/sprite_nodes/CCSprite.cpp draw 591
07-26 11:33:36.826: D/cocos2d-x debug info: OpenGL error 0x0502 in C:/dev/cocos2d-x/game/proj.android/…/…/cocos2dx/sprite_nodes/CCSprite.cpp draw 591
07-26 11:33:38.448: W/Adreno200-ES20: <*load_uniform_matrix:801>: GL_INVALID_OPERATION
07-26 11:33:38.448: D/cocos2d-x debug info(12221): OpenGL error 0x0502 in C:/dev/cocos2d-x/game/proj.android/…/…/cocos2dx/sprite_nodes/CCSprite.cpp draw 591

Anyone knows how to deal with this problem?
The onCreate method runs, because when I put any log on that it appears on logCat. It seems like I need to initialize something from cocos, could anyone help me if this problem?

Thanks,
Thiago

When you click notification, android tries to start yet one activity. You have nothing to do with code, just edit AndroidManifest: add android:launchMode="singleInstance"

See also here: http://developer.android.com/guide/topics/manifest/activity-element.html

Hi Sergey, thanks for your repply, I tried that but didn’t work for me.
I have an alert on onResume with a Toast message and it works, but the scree is still black and logCat with a lot of those exceptions in background.

Do you any idea how to deal with this? Maybe another tag in AndroidManifest?

Tks,
Thiago

Does it happens when you just press home and than resume back? If not, than android definitely tries to run yet one activity. So use this tag in AndroidManifest, but google it for more examples if it doesn’t work immediately.

Code from working game where single instance preference works correctly: <activity android:launchMode="singleTask">.

The same problem. Solved?