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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:13:14+00:00 2026-06-13T10:13:14+00:00

I want to display a toast message in a static class but the is

  • 0

I want to display a toast message in a static class but the is an issue of Toast message parameter passing context of application. Pleas help me, how to display the toast message in static class. Please recommend me the change that I have need to do, I will be very thankful to you. Here is a portion of my code.

    public class MainActivity extends Activity {
         public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.training_four_position);
            mEndlessRunnable = (Runnable) new UpdateRunnable();
            mEndlessRunnable.run();
    }


   private static class UpdateRunnable implements Runnable  {
   private int mState; 

   public UpdateRunnable(Handler handler, Button[] buttons) {
         mHandler = handler;
         mButtons = buttons;
   }

    public void run() {
        switch (mState) {
        case 0:
               mState = 1;
               break;
        case 1:

            mState = 0;
               // Here is the issue in my toast message
               Toast.makeText(CONTEXT, "Toast message.",Toast.LENGTH_LONG).show();
                break;
     }

  mHandler.postDelayed(this,1000)); 

  }// End of run()
  }//End of class UpdateRunnable
  } //End of MainActivity
  • 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-13T10:13:15+00:00Added an answer on June 13, 2026 at 10:13 am

    you can try to make a separate method for your toast

    public void showToast(String message){
    
        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
    
    }//end showToast
    

    and then call that in your inner class.

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

Sidebar

Related Questions

In my code,I want to display TextView text name as Toast message. I do
I want to display toast message inside timer and I used the following code
Hai Friends, I want to display a toast message to the user, when there
i want to display a msg to the user (msg box or Toast) when
I have a simple quiz application and I want display a nice timer /
i want to display a toast when two spinner values are same, and revert
this all started because I wanted to display a toast message in a background
Is it able to put views to the left, but off-screen? I want display
How I can display a message for a few seconds without using Toast on
I have developed one application which has 15 screens. Now I want to display

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.