Mukund
Mukund

Reputation: 1105

How to show toast in application when a page redirects in android?

I created an application in android to connect to mongodb. the programs main page consists of a loading a webpage via webview in my system, i used apache as application server. in apache, inside www folder all my php and html pages are there , and i am able to load those pages, and from that page i can go to all the pages and back via the application itself, my question is that while i go from one page to another, can a toast messege be shown in the screen?. i mean as a notification can a toast message be displayed when a page link is clicked from the emulator?

Upvotes: 0

Views: 1321

Answers (2)

Simon Dorociak
Simon Dorociak

Reputation: 33495

i mean as a notification can a toast message be displayed when a page link is clicked from the emulator?

If you want to show a message to User when "URL are going to be loaded" you need to assign WebViewClient to your WebView.

All what you need to do is override for example onPageStarted() method1:

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
   // show message to Use
   Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}

1Or also you can override shouldOverrideUrlLoading() method.

Upvotes: 1

Paresh Mayani
Paresh Mayani

Reputation: 128428

my question is that while i go from one page to another, can a toast message be shown in the screen?. i mean as a notification can a toast message be displayed when a page link is clicked from the emulator?

=> Yes you can use WebViewClient for your WebView to achieve that. You can write Toast notification code inside shouldOverrideUrlLoading() method.

Upvotes: 1

Related Questions