java - preloading a webview and then switching to its activity -
im new android , java programming. im trying get splash screen load on startup , in background load webview located on different activity , once webview page ready want switch activity 1 webview
package com.example.troyalert; import android.app.activity; import android.os.asynctask; import android.os.bundle; import android.view.menu; import android.webkit.websettings; import android.webkit.webview; import android.webkit.webviewclient; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_splash); new downloadwebpagetask().execute(); } private class downloadwebpagetask extends asynctask<void, void, void> { @override protected void doinbackground(void... arg0) { webview mywebview = (webview) findviewbyid(r.id.webview); websettings websettings = mywebview.getsettings(); websettings.setjavascriptenabled(true); mywebview.loadurl("http://enigmamaster.com/raul/locator3/"); mywebview.setwebviewclient(new webviewclient(){ @override public void onpagefinished(webview view, string url){ setcontentview(r.layout.activity_main); } }); return null; } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
the app crashes on doinbackground() im pretty sure cause not seeing webview view on splash screen. how can make work once page in webview loaded switches activity_main layout. reason wanting dont want people presented white screen while waiting page load in it
05-13 14:34:37.174: e/trace(1070): error opening trace file: no such file or directory (2) 05-13 14:34:37.814: w/dalvikvm(1070): threadid=11: thread exiting uncaught exception (group=0x40a13300) 05-13 14:34:37.894: d/gralloc_goldfish(1070): emulator without gpu emulation detected. 05-13 14:34:38.474: e/androidruntime(1070): fatal exception: asynctask #1 05-13 14:34:38.474: e/androidruntime(1070): java.lang.runtimeexception: error occured while executing doinbackground() 05-13 14:34:38.474: e/androidruntime(1070): @ android.os.asynctask$3.done(asynctask.java:299) 05-13 14:34:38.474: e/androidruntime(1070): @ java.util.concurrent.futuretask$sync.innersetexception(futuretask.java:273) 05-13 14:34:38.474: e/androidruntime(1070): @ java.util.concurrent.futuretask.setexception(futuretask.java:124) 05-13 14:34:38.474: e/androidruntime(1070): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:307) 05-13 14:34:38.474: e/androidruntime(1070): @ java.util.concurrent.futuretask.run(futuretask.java:137) 05-13 14:34:38.474: e/androidruntime(1070): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 05-13 14:34:38.474: e/androidruntime(1070): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 05-13 14:34:38.474: e/androidruntime(1070): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 05-13 14:34:38.474: e/androidruntime(1070): @ java.lang.thread.run(thread.java:856) 05-13 14:34:38.474: e/androidruntime(1070): caused by: java.lang.nullpointerexception 05-13 14:34:38.474: e/androidruntime(1070): @ com.example.troyalert.mainactivity$downloadwebpagetask.doinbackground(mainactivity.java:24) 05-13 14:34:38.474: e/androidruntime(1070): @ com.example.troyalert.mainactivity$downloadwebpagetask.doinbackground(mainactivity.java:1) 05-13 14:34:38.474: e/androidruntime(1070): @ android.os.asynctask$2.call(asynctask.java:287) 05-13 14:34:38.474: e/androidruntime(1070): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) 05-13 14:34:38.474: e/androidruntime(1070): ... 5 more 05-13 14:39:38.700: i/process(1070): sending signal. pid: 1070 sig: 9
try :
private webview mywebview; private websettings websettings; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_splash); mywebview = (webview) findviewbyid(r.id.webview); websettings = mywebview.getsettings(); websettings.setjavascriptenabled(true); new downloadwebpagetask().execute(); mywebview.setwebviewclient(new webviewclient(){ @override public void onpagefinished(webview view, string url){ setcontentview(r.layout.activity_main); } }); } private class downloadwebpagetask extends asynctask<void, void, void> { @override protected void doinbackground(void... arg0) { mywebview.loadurl("http://enigmamaster.com/raul/locator3/"); return null; } }
Comments
Post a Comment