I am newbie in cocos2d game development and developed 50% game using of Cocos2d SDK Android.I am stuck when the user plays certain level of game more than 3 times then i have to
Okay, the fundamental thing you have to remember with Cocos2d is that your ccScenes/Layers etc are all running INSIDE an activity.
what you need is to create and expose a Handler on your activity, and post a Runnable to that handler from your CCLayer.
You could then inflate a layout containing a WebView and a 'close' button in that runnable and attach them to the content view.
from there it's just a matter of attaching an onClick to the close button to set that layout to View.GONE and remove the objects, and you should be well away.
hope this helps
I've had to do this on my app, from the main menu layer, to show the web based tutorial page, and it works a treat.
} else if (i==TUTORIAL) {
//call load web url here
Handler handler = HomeMenu.getHandler();
handler.post(new Runnable() {
public void run() {
HomeMenu activity = HomeMenu.getInstance();
LayoutInflater inflater = (LayoutInflater)activity.getLayoutInflater();
if(inflater != null)
{
baseLayout = inflater.inflate(R.layout.tutoriallayout, null);
} else {
throw new IllegalStateException("Unable to find view inflater");
}
WebView wv = (WebView) baseLayout.findViewById(R.id.tutorialWeb);
wv.loadUrl( "http://url to your tutorial here" );
ImageView iv = (ImageView) baseLayout.findViewById(R.id.closeTutorial);
iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (baseLayout != null) {
baseLayout.setVisibility(View.GONE);
}
baseLayout = null;
}
});
activity.addContentView(baseLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
}
});
break;
}
and a layout such as
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/absoluteLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<RelativeLayout android:id="@+id/rLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="10dip">
<android.webkit.WebView android:id="@+id/tutorialWeb" android:layout_height="fill_parent" android:layout_width="fill_parent" android:padding="10dip"></android.webkit.WebView>
</RelativeLayout>
<ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/delete" android:id="@+id/closeTutorial" android:adjustViewBounds="true" android:clickable="true"></ImageView>
</AbsoluteLayout>