Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:22:14+00:00 2026-06-01T19:22:14+00:00

I’m developing a game for android, and I’ve been trying to implement a dialog

  • 0

I’m developing a game for android, and I’ve been trying to implement a dialog to show a webview for web banner ads. (I’m using cocos2d for my development). Im using the static method ads() to open the dialog statically. Since doing this, however, I’ve started having problems launching.

On first launch, it runs fine, but when the app is closed and reopened, the “openscreen” scene starts but then doesn’t play run its fade in and fade outs or continue into the menu scene.

Activity (where the ads() method is)

package wingdev.defence;

import java.util.Timer;
import java.util.TimerTask;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.opengl.CCGLSurfaceView;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Button;

public class DefenceActivity extends Activity{
        protected CCGLSurfaceView _glSurfaceView;
        public static int highscore = 0;
        public static int mode= Activity.MODE_PRIVATE;
        public static SharedPreferences  mySharedPreferences ;
        public static String CurrentLevel = "";
        public static boolean firstlaunch=true;
        public static int screenforchoice = 0;
        public static boolean choicemade=false;
        public static boolean choice=false;
        public static DefenceActivity  context;

            @Override
                    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            _glSurfaceView = new CCGLSurfaceView(this);
            setContentView(_glSurfaceView);
            CCScene scene = OpenScreen.scene();
            CCDirector.sharedDirector().runWithScene(scene);
        }

        @Override

        public void onStart()

        {
            super.onStart();
            CCDirector.sharedDirector().attachInView(_glSurfaceView);
            CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationLandscapeLeft);

            CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);
            mySharedPreferences=getSharedPreferences("HighScore",mode);
            highscore= mySharedPreferences.getInt("HighScore",0);
            SharedPreferences.Editor editor= mySharedPreferences.edit();
                editor.remove("HighScore");
                editor.putInt("HighScore", highscore);
                editor.commit();
                CCScene scene = OpenScreen.scene();
            CCDirector.sharedDirector().runWithScene(scene);
            Config.context = this;
            context = this;
            }
        public void startgame()
            {
            CCDirector.sharedDirector().attachInView(_glSurfaceView);

            CCDirector.sharedDirector().setDeviceOrientation(CCDirector.kCCDeviceOrientationLandscapeLeft);;

            CCDirector.sharedDirector().setAnimationInterval(1.0f / 60.0f);

            CCScene scene = GameLayerSurvival.scene();
            CCDirector.sharedDirector().runWithScene(scene);

            }
        @Override
        public void onPause()
        {
            super.onPause();
            CCDirector.sharedDirector().pause();
        }

        @Override
        public void onResume()
        {
            super.onResume();
        }
        @Override
        public void onStop()
        {
            super.onStop();
            finish();

            CCDirector.sharedDirector().end();
        }
        static public void newhighscore()
        {if(GameLayerSurvival.score>highscore){
        highscore=GameLayerSurvival.score;
        }
        SharedPreferences.Editor editor= mySharedPreferences.edit();
        editor.remove("HighScore");
        editor.putInt("HighScore", highscore);
        editor.commit();
        }

        public static void ads(){
        context.runOnUiThread(new Runnable() {
        public void run() {
        final Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.main);
        dialog.setTitle("Advert");
        dialog.setCancelable(true); 
        WebView mWebView = (WebView) dialog.findViewById(R.id.webbanner);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.example.co.uk/");
        Button bc_btn1 = (Button) dialog.findViewById(R.id.button1);
        bc_btn1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v){
                killDialog(dialog);
            }
        });
        dialog.show();
            }
        });
        }
        public static void killDialog(Dialog dialog){
            dialog.cancel();
        }
}

Openscreen- the first scene used on launch

package wingdev.defence;

import org.cocos2d.actions.instant.CCCallFunc;
import org.cocos2d.actions.interval.CCDelayTime;
import org.cocos2d.actions.interval.CCFadeIn;
import org.cocos2d.actions.interval.CCFadeOut;
import org.cocos2d.actions.interval.CCSequence;
import org.cocos2d.layers.CCColorLayer;
import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCLabel;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.types.CGSize;
import org.cocos2d.types.ccColor4B;

public class OpenScreen extends CCColorLayer {

CCLabel _start; 
CCLabel _easy; 
CCLabel _normal; 
CCLabel _highscore; 
CCLabel _howto; 
CCLabel _hard; 
CCLabel _reset;
CCSprite wingdev = CCSprite.sprite("wingdevpresents.png");
CCSprite darkorange = CCSprite.sprite("PirateTea.png");
CCSprite plane = CCSprite.sprite("plane.png");
CCSprite back2 = CCSprite.sprite("black.png");
public static CCScene scene()
{ 
    //
    CCScene scene = CCScene.node();
    CCColorLayer layer = new OpenScreen(ccColor4B.ccc4(255, 255, 255, 255));
    scene.addChild(layer);

    return scene;
}
protected OpenScreen(ccColor4B color) {
super(color);
CGSize winSize = CCDirector.sharedDirector().displaySize();
this.setIsTouchEnabled(true);
back2.setPosition(winSize.width / 2.0f, winSize.height / 2.0f);
back2.setScaleX(winSize.width / back2.getContentSize().width);
back2.setScaleY(winSize.height / back2.getContentSize().height);
addChild(back2);
wingdev.setPosition(winSize.width / 2.0f, winSize.height / 2.0f);
wingdev.setScaleX(winSize.width / wingdev.getContentSize().width);
wingdev.setScaleY(winSize.height / wingdev.getContentSize().height);
addChild(wingdev);
wingdev.runAction(CCSequence.actions(CCFadeIn.action(1.0f),CCDelayTime.action(2.0f),CCFadeOut.action(1.0f), CCCallFunc.action(this,"openscreen2")));
}
public void openscreen()
{   
    CCDirector.sharedDirector().replaceScene(Menu.scene());
}
public void openscreen2(){
    CGSize winSize = CCDirector.sharedDirector().displaySize();
    removeChild(wingdev,true);
    darkorange.setPosition(winSize.width / 2.0f, winSize.height / 2.0f);
    darkorange.setScaleX(winSize.width / darkorange.getContentSize().width);
    darkorange.setScaleY(winSize.height / darkorange.getContentSize().height);
    addChild(darkorange);
        darkorange.runAction(CCSequence.actions(CCFadeIn.action(1.0f),CCDelayTime.action(2.0f),CCFadeOut.action(1.0f),CCCallFunc.action(this,"openscreen")));
}
}

Any help in understanding where I’m going wrong would be very appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:22:17+00:00Added an answer on June 1, 2026 at 7:22 pm

    You pause your CCDirector in

     @Override
     public void onPause()
     {
      super.onPause();
      CCDirector.sharedDirector().pause();
     }
    

    I think you need to start it again in onResume()

     @Override
     public void onResume()
     {
      super.onResume();
      CCDirector.sharedDirector().resume();
     }
    

    onStart() won’t get called if the app is not killed.

    http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.