Reputation: 10100
In my app, there are two activities.First is Splashscreen and second is Webview activity. After splash screen displays,i want to show my webview activity.But after splashscreen,for 2-3 seconds a blank white screen comes and then webview activity gets loaded.Any idea of how to ignore this white screen. I looked into the solution for this issue in many posts but without success. Any help will be appreciated.
Adding the code : Splashscreen Activity :
@Override
protected void onStart() {
super.onStart();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
startActivity(new Intent(SplashScreen.this,
WebViewActivity.class));
}
}, DELAY);
}
Upvotes: 2
Views: 3167
Reputation: 931
Working code
public class WebActivity extends Activity {
protected boolean _active = true;
protected int _splashTime = 3000;
Thread splashTread;
private boolean stop = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
if(!stop){
startActivity(new Intent(WebActivity.this,Home.class));
finish();
}
else
finish();
}
}
};
splashTread.start();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
if(splashTread.isAlive())
this.stop = true;
}
return true;
}
}
Upvotes: 1
Reputation: 931
create two class files like WebActivity.java,home.java.
WebActivity.java
Handler handler = new Handler();
// run a thread after 2 seconds to start the home screen
handler.postDelayed(new Runnable() {
@Override
public void run() {
// make sure we close the splash screen so the user won't come
// back when it presses back key
finish();
// start the home screen
ProgressDialog pd = new ProgressDialog(WebActivity.this);
//use this before calling intent
pd.setMessage("Processing...");
pd.show();
Intent intent = new Intent(WebActivity.this, Home.class);
WebActivity.this.startActivity(intent);
}
}, 2000); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called
Home.java
webview=(WebView)findViewById(R.id.webView1);
webview.setWebViewClient(new myWebClient());
webview.loadUrl("http://www.google.com");}
public class myWebClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
Android manifest
Just add the activity class and set internet permission to load webview
Upvotes: 0
Reputation: 931
After completing the splash screen, the webpage load take some time. That's why you see a blank white screen appearing. Once web view starts load a progress bar. try this link . It will helpful to you. http://www.technotalkative.com/android-load-webview-with-progressbar/
Upvotes: 0