I've trying for days now to get a solution to show a splash screen while loading a webview.
I've looked around and there are several approaches:
- make activity just to show splash screen, wait a few seconds and then start the webview activity -> this is not a solution since all the loading is again done after splash screen is closed
second approach is something like this:
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
findViewById(R.id.webview).setVisibility(View.VISIBLE);
//hide loading image
findViewById(R.id.imageView1).setVisibility(View.GONE);
//show webview
}
});
This works, but again there is a slight appearance of a white screen while transitioning to webview. And also you can't control the timing of your splash screen.
third solution is something that I'd like to make, but (even after few days of searching and trying) don't know how -> show splash screen in one thread, prepare everything for a webview in another and then simply switch to webview.
My question is, can anybody show me where to start with this third solution?
I wanted to try something like this! but I couldn't figure out how to pass webview to another activity and from what I read, this is not even a good idea.
Any suggestion, ideas, pointers? Is there a way to show splash screen, prepare(inflate) webview in another thread and then switch to it after loading url (and everything else) is done?
Thanks!!!
Try to use a WebChromeClient on the Webview. In the WebChromeClient, you have a method onProgressChange.
You can do disappear the splash screen when the onProgressChange tell you that the page are finish to load.
Edit:
You can call in a thread your Url with HttpGet for example and retrieve the response. When you have the response you can load the webview with the loadData(...) method.
Related
hello im makeing a vwe browser app and it have a faw problem and dont know which part of the code i post
bookmark activity when i go to the bookmark activity it opens fine but when i switch back to the webview it reload to the homepage not the last page it was in PS it don't reloads when the screen change Orientation
its kind of slow
open videos like youtube but don't let them go full screen
ourview = (WebView) findViewById(R.id.webView1);
ourview.getSettings().setJavaScriptEnabled(true);
ourview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
ourview.getSettings().setLoadWithOverviewMode(true);
ourview.getSettings().setSupportZoom(true);
ourview.getSettings().setBuiltInZoomControls(true);
ourview.getSettings().getAllowFileAccess();
ourview.getSettings().getAllowFileAccessFromFileURLs();
ourview.getSettings().getJavaScriptCanOpenWindowsAutomatically();
ourview.getSettings().setLoadsImagesAutomatically(true);
ourview.loadUrl("http://www.google.com");
Switching between different activities,will always call onCreate() method.
So since your ourview.loadUrl("http://www.google.com"); is in onCreate() method,
it is called each time when you switch between those activities.
That is why webView reload to homepage when switching between activities.
I am using Twitter4j but I need to authenticate a user with oAuth. The user needs to get a pin and input it into the app. When I load a webview with the url and the user accept's to give the app privileges, they receive a pin. How would they close the webview in order to input the pin. I cant close the webview in the emulator. Below is the method in the Async class where the webview is shown after the url is retrieved.
protected void onPostExecute(String url) {
WebView webview = new WebView(MainActivity.this);
setContentView(webview);
webview.loadUrl(url);
}
You can't "close" a WebView. What you could do is hide it. Maybe this solution will shed some light - Hide WebView until JavaScript is done
Well, you could
instead use another dedicated activity with mainly a webview [potentially also with 'done' button]. You could start that activity from your onPostExecute with intent, and then you will go back when user is done with it, or you could start that webview activity for result
Another option is to replace your webview when you are done with another view, for example by calling setContentView with another layout. I never did this myself, and not sure it will work easily, but I found that some people recommend using ViewFlipper for similar effect.
Hope that helps.
You can call finish() from anywhere inside the Activity class
This works for me:
webview.destroy();
Add a close button and on its click set:
webview.setVisibility(View.INVISIBLE);
webview.loadUrl("");
You can then reduce the height width of the web view to minimum.
I use activity with ImageView, and by click on button it switches to activity with VideoWiew and plays movie, the movies first frame is the image on previous activity. I disabled animation between activity by using
Intent intent = new Intent(ImageClass.this, MovieClass.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
but it still flashes black screen between them, how can i disable this?
One of the simplest way is to move all the expensive (time-consuming) processing from your activity's onCreate and onStart method to onResume mthod. By this, your newly launched activity will be visible right after its launched but then will take a little extra to make it available for user to interact. Further, I would suggest you to move all the heavy lifting in AsyncTask for smoother UI experience.
I recently had a problem with smooth transition. Even though I am loading the lengthy tasks in AsyncTask, it still takes time to load, and the screen has to wait.
If you have a WebView, for example, that takes a while to load, and under the WebView, you have some TextViews and other things, supposedly a layout.
The layout will load first, and the WebView later, making the screen loading ackward.
A solution for this would be to set the Visibility to GONE on all the objects before it loads, and then set to VISIBLE after the WebView loads.
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
webView.setVisibility(View.VISIBLE);
LinearLayout ll_load_after_web_view_bottom = findViewById(R.id.ll_load_after_web_view_bottom);
LinearLayout ll_load_after_web_view_top = findViewById(R.id.ll_load_after_web_view_top);
ll_load_after_web_view_bottom.setVisibility(View.VISIBLE);
ll_load_after_web_view_top.setVisibility(View.VISIBLE);
}
});
Previously when using a webview in android, clicking any link would force the "proper" browser to open and then web browsing would continue in that instance.
However this seems to no longer be the case. The following code results in all links staying inside the webview, but I actually want the links to launch a new browser instance. Did this change in 2.3 ?
Note I am asking the opposite of what most people ask (they ask how to keep all links inside the webview, I want them to launch outside)
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView view = new WebView(this);
setContentView(view);
view.loadUrl("http://news.bbc.co.uk");
}
}
EDIT: Clarification - the first URL will load in the WebView and all subsequent clicks will open in a new browser. This is simplification from what I really want, but good enough.
Bascially the problem is, previously clicking a link would open a new browser session. Most people don't want that (hence the questions on here about it) but I do. However for some reason now it seems to load in the webview all the time (2.3 perhaps?)
Let me understand. Do you want to launch the first webpage in the same webview, while the other hyperlinks to go to the default browser, or you want the default browser itself to open for the first link clicked?
If it's the first case, I don't exactly know, unless you know some way to gather the link URL from the webview.
For the second instance, i.e. launching the default browser for any URL click, just skip (remove) this line: view.setWebViewClient(new WebViewClient() { });, which will open all the links in the default browser, and not the webview itself.
Houps, wrong answer, I misunderstood your question.
Need to delete...
Is there anyway I can open web when user clicks on TextView, in a new window without leaving the app, it's like in iPhone when you click on an URL it shows you a new browser window, but there is a BACK button you can click to go back to previous screen?
Thanks!
You can create your own Browser Activity with a WebView in the layout. Inherently it is not going to have any of the functionality of the actual stock browser app though, other than displaying the web page. You'll have to add in the forward / back buttons if you want them and anything else you need. If you don't need any of that stuff then you should be fine with just a plain WebView. When you press the back button on the device it should close that activity and take you back to the one you started in.
Edit:
To get callbacks from a WebView when the user clicks a link you can use the WebViewClient shouldOverrideUrlLoading() method, like this:
wv.setWebViewClient(new WebViewClient() {
/* On Android 1.1 shouldOverrideUrlLoading() will be called every time the user clicks a link,
* but on Android 1.5 it will be called for every page load, even if it was caused by calling loadUrl()! */
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.i(myTag, url);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)) ;
startActivity(i);
return true;
}
});
For a TextView its a little bit more work, You'll have to make your own copy of the Linkyfy class and use a TransformFilter to make the links behave however you want them to. Check out this question for an example Android Linkify both web and #mentions all in the same TextView
Maybe a WebView is what you want.