How to display Toast in Android

0 votes

I have a slider that can be lifted to see a map. To show or hide the map, I can slide the slider up or down. I can manage touch events on the map while it is in front of me. An AsyncTask is launched each time I touch the screen, downloading data as it goes and creating a Toast that displays it. Despite starting the task upon touch event, no toast is shown until the slider is closed. The Toast occurs after the slider has been closed and the map has been hidden.

Any ideas?

Well start the task

EDIT:

public boolean onTouchEvent(MotionEvent event, MapView mapView){ 
    if (event.getAction() == 1) {
        new TestTask(this).execute();
        return true;            
    }else{
        return false;
    }
 }

and in onPostExecute make a toast

Toast.makeText(app.getBaseContext(),(String)data.result, 
                Toast.LENGTH_SHORT).show();

In new TestTask(this), this is a reference to MapOverlay and not to MapActivity, so this was the problem.

Nov 4, 2022 in Android by Edureka
• 13,620 points
1,455 views

1 answer to this question.

0 votes

Use the show() function of the Toast class to display the toast message you produced.​

Syntax:

public void show ()

The code to show the Toast message:

Toast.makeText(getApplicationContext(),
               "This a toast message",
               Toast.LENGTH_LONG)
     .show();
answered Nov 8, 2022 by Edureka
• 12,690 points

Related Questions In Android

0 votes
0 answers

How to make grid view scroll horizontally not vertically in android?

I use a flexible Grid View. means ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,620 points
553 views
0 votes
1 answer
0 votes
1 answer

How to set my Activity as main activity in android?

The "intent-filter" in "AndroidManifest.xml" allows you to ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 13,620 points
2,382 views
0 votes
0 answers
0 votes
0 answers

Android Grid View Scroll Horizontally

I'm working on a job that pulls ...READ MORE

Sep 22, 2022 in Android by Edureka
• 13,620 points
1,034 views
0 votes
1 answer

Simple Android RecyclerView example

Begin with a blank activity. The actions ...READ MORE

answered Nov 10, 2022 in Android by Edureka
• 12,690 points
641 views
0 votes
1 answer

Running docker on Android

According to the documentation, the Android kernel is ...READ MORE

answered Aug 1, 2018 in Docker by Kalgi
• 52,350 points
3,804 views
0 votes
1 answer

How to turn on front flash light programmatically in Android?

For this problem you should: Check whether the ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 12,690 points
1,692 views
0 votes
1 answer

Android in-app billing - How to handle refunds ?

Simply disregard the library's purchase to overcome ...READ MORE

answered Nov 10, 2022 in Android by Edureka
• 12,690 points
1,573 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP