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 8924049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:18:07+00:00 2026-06-15T07:18:07+00:00

Here is the thing I have a handler that shows a message on screen

  • 0

Here is the thing I have a handler that shows a message on screen when I touch an area where the color of the background is white.

                  else if (ct.closeMatch (Color.WHITE, touchColor, tolerance))             

                               {  Random r = new Random();
                           int txt= r.nextInt(6-0) + 0;
                           if(txt==0){ variables.pointtxt = "Nothing interesting"; }
                           else if (txt==1){ variables.pointtxt = "There´s nothing there"; }     
                           else if (txt==2){ variables.pointtxt = "I can´t do nothing with that"; } 
                           else if (txt==3){ variables.pointtxt = "Wait... nop nothing"; }  
                           else if (txt==4){ variables.pointtxt = "Nothing"; }  
                           else if (txt==5){ variables.pointtxt = "More nothing"; }
                                LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                                  View popupView = layoutInflater.inflate(R.layout.popup, null);  
                                       final PopupWindow popupWindow = new PopupWindow(
                                          popupView, 
                                          LayoutParams.FILL_PARENT,  
                                                 LayoutParams.WRAP_CONTENT);
                                          TextView text = (TextView) popupView.findViewById(R.id.popuptxt);
                                        text.setText(variables.pointtxt);

                                        popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 250) ;




                                new Handler().postDelayed(new Runnable()
                                {
                                    public void run()
                                      {      if (popupWindow.isShowing()== true)

                                         popupWindow.dismiss();

                                      }
                                }, 1000);




                                   }

But if I run a new intent in les than 1000 miliseconds it crashes, I´m pretty sure because it couldn finish the handler cue.

Is it any way to tell the handler that if the aplication is closing then run popupWindow.dismiss(); ?

or inted is there a way to tell when I call ( when touching something red )

   if (ct.closeMatch (Color.RED, touchColor, tolerance)) {


                       Intent game = new Intent(lvl2_1_0.this, lvl2_1_1.class); 
                       game.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                          game.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                        startActivity(game);



                  }

To finish all handler cues?

I´v been searching and I can´t find a way to force finish all the handlers in an aplication before finishing it.

I know I´m pushing it a little maybe but in some cases when I test the game it crashes, of course maybe in normal playing it won´t happen because it´s unprobable to press the button to pass the screen in les than 1000 milliseconds after apearing the popup But it bothers me to have that error on my hands.

Thanks to your answers in other threads I´v learned the most about programing for android so THANK YOU !

This is the code Fixed Thanks to sam ! 😛

public class lvl2_1_0 extends Activity implements View.OnTouchListener {
private PopupWindow popupWindow;
private Handler mHandler = new Handler();
private Runnable dismissPopup = new Runnable() {
        public void run() {
            if (popupWindow.isShowing())
                popupWindow.dismiss();
        }
    };
   @Override
    public void onCreate(Bundle savedInstanceState) {

Then

call the popup. In my case:

   LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                                  View popupView = layoutInflater.inflate(R.layout.popup, null);  
                                  popupWindow = new PopupWindow(
                                          popupView, 
                                          LayoutParams.FILL_PARENT,  
                                                 LayoutParams.WRAP_CONTENT);
                                          TextView text = (TextView) popupView.findViewById(R.id.popuptxt);
                                        text.setText(variables.pointtxt);

                                        popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 250) ;



                                        mHandler.postDelayed(dismissPopup, 3000);

Finally close the aplication in without Force close

                       Intent game = new Intent(lvl2_1_0.this, lvl2_1_1.class); 
                       game.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                          game.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                          mHandler.removeCallbacks(dismissPopup);
                        startActivity(game);
  • 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-15T07:18:09+00:00Added an answer on June 15, 2026 at 7:18 am

    But if I run a new intent in les than 1000 miliseconds it crashes, I´m pretty sure because it couldn finish the handler cue.

    Handler#removeCallbacks(Runnable) will cancel the passed Runnable f it is waiting in the queue.

    Create two field variables to save a reference to your Handler and Runnable:

    public class Example extends Activity {
        private Handler mHandler = new Handler();
        private Runnable dismissPopup = new Runnable() {
            public void run() {
                if (popupWindow.isShowing())
                    popupWindow.dismiss();
            }
        }
    

    Now where you previously called new Handler().postDelayed(new R... use:

    mHandler.postDelayed(dismissPopup, 1000);
    

    Finally just before you launch the new Intent call:

    ...
    mHandler.removeCallbacks(mRunnable);`
    startActivity(game);  
    

    (You might want to call removeCallbacks() in onPause() as well.)

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

Sidebar

Related Questions

Here is the thing. I currently have a tabBar controller, with several navigation controllers
Here's the thing. I have an interface, and I would to put the Include
Here is the thing. Right now I have this e-commerce web site where people
I have some doubt on wget command. Here is the thing I want to
I have a problem with docking. Here is the thing. I hope I can
CSS newbie here. Strange thing is happening, I have gaps between links, and I
We have an application that handling our own message - a timered procedure read
I think I have got something simple wrong here. I am trying to pass
Going round in circles here i think. I have an activity called Locate; public
Really quick here... I think I have the answer, but just looking for some

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.