Toast Messages in Android

I'm developing a game via Andengine for Android platforms. I created a LevelEditorScene and I wanna use Toast messages on it like:

 Toast.makeText(activity, " Upload Started ...", Toast.LENGTH_SHORT).show();

But it creates an error. Here is the logCat: http://s9.postimg.org/jfqwsvx7j/Captu1re.png

What is the problem, can u solve it?


Here are my whole codes:

LevelEditorScene.java

@Override
public void createScene()
{

    //ekrana eleman eklemek i├žin
    setOnSceneTouchListener(this);



     Rectangle save = new Rectangle(100, 400, 80, 50, vbom){
           @Override
            public boolean onAreaTouched(TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {

               if(pTouchEvent.getAction() == MotionEvent.ACTION_DOWN)
               {
                   Toast.makeText(activity, " Upload Started ...", Toast.LENGTH_SHORT).show();





                 /*  getAllObjectsData();
                   createXmlFile(x, y, distanceordirection, type);
                   */

               }
               return true;
           }
        };
     save.setColor(1.0f,0.4f,0.5f);
     registerTouchArea(save);
     attachChild(save);
  }

SceneManager.java

 public void loadEditorScene(final Engine mEngine)
{
    setScene(loadingScene);
    ResourcesManager.getInstance().unloadMenuTextures();
    mEngine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() 
    {
        public void onTimePassed(final TimerHandler pTimerHandler) 
        {
            mEngine.unregisterUpdateHandler(pTimerHandler);
            ResourcesManager.getInstance().loadGameResources();
            editorScene = new LevelEditorScene();
            setScene(editorScene);
        }
    }));
}

GameActivity.java

     public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) throws IOException
{
    mEngine.registerUpdateHandler(new TimerHandler(2f, new ITimerCallback() 
    {
            public void onTimePassed(final TimerHandler pTimerHandler) 
            {
                mEngine.unregisterUpdateHandler(pTimerHandler);
                SceneManager.getInstance().createMenuScene();
            }
    }));
    pOnPopulateSceneCallback.onPopulateSceneFinished();
}

Answers


runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(activity.this, "message", Toast.LENGTH_SHORT).show();

                            }
                        });

if you use Toast in static function it must not work

you can do this add this before oncreate function:

static Activity thisActivity = null;

and in oncreate function:

thisActivity = this;

and then you can use Toast:

Toast.makeText(thisActivity , "message", Toast.LENGTH_SHORT).show();

Need Your Help

Programmatically connect Silverlight to WCF

c# .net wcf silverlight

I have inherited a Silverlight application that consumes a WCF service, and is hosted in an ASP.NET web form. The application needs to run over HTTP and HTTPS, and will be installed on a customer's...

How is it possible, that ajaxing is much more slower in Chrome and IE than Mozilla?

javascript jquery ajax

I would like to ask you to find the point, why the site -I'm working on- is slow.