This code snippet helps you to open browser in android cocos2D application
public void openBrowser(){ CCDirector.sharedDirector().getActivity().runOnUiThread(new Runnable() { public void run() { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); CCDirector.sharedDirector().getActivity().startActivity(browserIntent); }}); }
Call this function anywhere inside your cocos2D project to open the browser with the corresponding URL.
Excuse me, I implemented this, but I would like to know how can I do it so that when I press the phone’s back button it goes back to the cocos2d layer that called the openBrowser method, when I press it, it restarts the game from the beginning
IF you have opened the browser from a cocos2DLayer then clicking on back button will bring you back to the previous cocos2d layer. Please check if you are not destroying the activity then the onPause() function is called on the activity when your browser is opened, this may be causing the game to restart.