Cocos2d-x C ++ notifies android to update the UI

Source: Internet
Author: User

One problem today is that the Game transplanted to Android displays ads on the main interface, and there are hidden ads in the game.

Let's look at my implementation methods.

1. When the game starts, a view is placed in the XML file on the Java side for advertisement placement. Initialize the ad code During oncreate.

2. After Entering the game, C ++ notifies Java through JNI (I have introduced how to use JNI) to hide the advertisement.

3. Hidden advertisements in Java:

Ui method updated in the main thread,

View Source Code

Print help

01 private
Handler mHandler =
new
Handler(){
02 @Override
03 public
void
handleMessage(Message msg) {
04 switch
(msg.what) {
05 case
UPDATE_UI: {
06 // Todo handle the hidden ad adview. setvisibility (view. Invisible) here );
07 break;
08 }
09 default:
10 break;
11 }
12 }
13 }

When Java receives a notification to hide the advertisement, it sends a message to update the UI.

 

1 void
hideAdView(){
2  
3 mHandler.sendEmptyMessageDelayed(UPDATE_UI, 0);
4  
5 }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.