android – webView在离线时不显示网站

android – webView在离线时不显示网站,第1张

概述我有一个应用程序向GCM注册推送通知.该代码工作正常,不是我的问题的根源.注册后,该应用程序只会在WebView中显示一个网站.到目前为止,如果设备的网络适配器已打开,这一切都很好. 如果关闭网络适配器,则应从缓存加载webview.这部分不起作用.我已经按照下面的教程并从中获取了一些部分,以便将网站页面保存在SD卡上保存的缓存中. 如果我运行该应用程序,则会显示该网站.如果我然后关闭网络适配器并 我有一个应用程序向GCM注册推送通知.该代码工作正常,不是我的问题的根源.注册后,该应用程序只会在WebVIEw中显示一个网站.到目前为止,如果设备的网络适配器已打开,这一切都很好.

如果关闭网络适配器,则应从缓存加载webvIEw.这部分不起作用.我已经按照下面的教程并从中获取了一些部分,以便将网站页面保存在SD卡上保存的缓存中.

如果我运行该应用程序,则会显示该网站.如果我然后关闭网络适配器并访问该网站,它将不会显示.我检查了SD卡上的缓存目录,并且部分站点已写入缓存.

为什么网站在离线时不会从缓存中加载?

是否可以将网页保留为缓存,直到说应用程序被卸载或android决定否则?

tutorial

本教程介绍如何在SD卡上创建目录并写入目录.目录确实存在,但在脱机模式下不会从此缓存中恢复webvIEw.

下面是我如何调用显示webvIEw的mainactivity.

Intent i = new Intent(getApplicationContext(),MainActivity.class);                //i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_top);                i.putExtra("name","hardcoded clIEnt name");                i.putExtra("email","hardcoded email");                startActivity(i);                finish();

.

这是完整的MainActivity.您可以忽略第一部分,因为这是处理GCM推送通知内容的代码,一切正常.我需要知道为什么webvIEw不会从缓存中加载.

import static com.bmi.bmitestapp.CommonUtilitIEs.disPLAY_MESSAGE_ACTION;import static com.bmi.bmitestapp.CommonUtilitIEs.EXTRA_MESSAGE;import static com.bmi.bmitestapp.CommonUtilitIEs.SENDER_ID;import java.io.file;import androID.app.Activity;import androID.content.broadcastReceiver;import androID.content.Context;import androID.content.Intent;import androID.content.IntentFilter;import androID.net.ConnectivityManager;import androID.net.NetworkInfo;import androID.os.AsyncTask;import androID.os.Bundle;import androID.util.Log;import androID.webkit.WebChromeClIEnt;import androID.webkit.WebSettings;import androID.webkit.WebVIEw;import androID.webkit.WebVIEwClIEnt;import androID.Widget.TextVIEw;import androID.Widget.Toast;import androID.webkit.*;import com.Google.androID.gcm.GCMRegistrar;public class MainActivity extends Activity {    private static final String TAG = MainActivity.class.getSimplename();    // label to display gcm messages    TextVIEw lblMessage;    WebVIEw webVIEw;    // Asyntask    AsyncTask<VoID,VoID,VoID> mRegisterTask;    // Alert dialog manager    AlertDialogManager alert = new AlertDialogManager();    // Connection detector    ConnectionDetector cd;    public static String name;    public static String email;    @OverrIDe    public voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        Log.e(TAG,"in onCreate in mainactivity");        cd = new ConnectionDetector(getApplicationContext());        // Check if Internet present//        if (!cd.isConnectingToInternet()) {//            // Internet Connection is not present//            alert.showAlertDialog(MainActivity.this,//                    "Internet Connection Error",//                    "Please connect to working Internet connection",false);//            // stop executing code by return//            return;//        }        // Getting name,email from intent        Intent i = getIntent();        name = i.getStringExtra("name");        email = i.getStringExtra("email");             // Make sure the device has the proper dependencIEs.        GCMRegistrar.checkDevice(this);        // Make sure the manifest was properly set - comment out this line        // while develoPing the app,then uncomment it when it's ready.        GCMRegistrar.checkManifest(this);        lblMessage = (TextVIEw) findVIEwByID(R.ID.lblMessage);        registerReceiver(mHandleMessageReceiver,new IntentFilter(                disPLAY_MESSAGE_ACTION));        // Get GCM registration ID        final String regID = GCMRegistrar.getRegistrationID(this);        // Check if regID already presents        if (regID.equals("")) {            // Registration is not present,register Now with GCM            GCMRegistrar.register(this,SENDER_ID);        } else {            // Device is already registered on GCM            if (GCMRegistrar.isRegisteredOnServer(this)) {                // Skips registration.                Toast.makeText(getApplicationContext(),"Already registered with GCM",Toast.LENGTH_LONG).show();            } else {                // Try to register again,but not in the UI thread.                // It's also necessary to cancel the thread onDestroy(),// hence the use of AsyncTask instead of a raw thread.                final Context context = this;                mRegisterTask = new AsyncTask<VoID,VoID>() {                    @OverrIDe                    protected VoID doInBackground(VoID... params) {                        // Register on our server                        // On server creates a new user                        ServerUtilitIEs.register(context,name,email,regID);                        return null;                    }                    @OverrIDe                    protected voID onPostExecute(VoID result) {                        mRegisterTask = null;                    }                };                mRegisterTask.execute(null,null,null);            }        }            webVIEw = (WebVIEw)findVIEwByID(R.ID.webVIEw1);            // Initialize the WebVIEw            webVIEw.getSettings().setSupportZoom(true);            webVIEw.getSettings().setBuiltInZoomControls(true);            webVIEw.setScrollbarStyle(WebVIEw.SCRolLbarS_OUTSIDE_OVERLAY);            webVIEw.setScrollbarFadingEnabled(true);            webVIEw.getSettings().setLoadsImagesautomatically(true);            webVIEw.getSettings().setDomStorageEnabled(true);            // Set cache size to 8 mb by default. should be more than enough            webVIEw.getSettings().setAppCacheMaxSize(1024*1024*8);            // This next one is crazy. It's the DEFAulT location for your app's cache            // But it dIDn't work for me without this line.            // UPDATE: no hardcoded path. Thanks to Kevin Hawkins            String appCachePath = getApplicationContext().getCacheDir().getabsolutePath();            Log.e(TAG,"appCachePath = " + appCachePath);            webVIEw.getSettings().setAppCachePath(appCachePath);            webVIEw.getSettings().setAllowfileAccess(true);            webVIEw.getSettings().setAppCacheEnabled(true);            // Load the URLs insIDe the WebVIEw,not in the external web browser            webVIEw.setWebVIEwClIEnt(new WebVIEwClIEnt());               if (savedInstanceState == null)                        {        if(isNetworkAvailable() == true){            Log.e(TAG,"we have a network connection");            webVIEw.getSettings().setCacheMode(WebSettings.LOAD_DEFAulT);            webVIEw.loadUrl("http://bmi.cubecore.co.uk");        } else {            Log.e(TAG,"we don't have a network connection");            webVIEw.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);            webVIEw.loadUrl("http://bmi.cubecore.co.uk");        }                        }     }      //end of oncreate    private boolean isNetworkAvailable() {        ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();        return activeNetworkInfo != null;    }    /**     * Receiving push messages     * */    private final broadcastReceiver mHandleMessageReceiver = new broadcastReceiver() {        @OverrIDe        public voID onReceive(Context context,Intent intent) {            String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);            // Waking up mobile if it is sleePing            WakeLocker.acquire(getApplicationContext());            /**             * Take appropriate action on this message             * depending upon your app requirement             * For Now i am just displaying it on the screen             * */            // Showing received message            lblMessage.append(newMessage + "\n");            Toast.makeText(getApplicationContext(),"New Message: " + newMessage,Toast.LENGTH_LONG).show();            // Releasing wake lock            WakeLocker.release();        }    };    @OverrIDe    protected voID onDestroy() {        super.onDestroy();        // Clear the cache (this clears the WebVIEws cache for the entire application)        //webVIEw.clearCache(false);        if (mRegisterTask != null) {            mRegisterTask.cancel(true);        }        try {            unregisterReceiver(mHandleMessageReceiver);            GCMRegistrar.onDestroy(this);        } catch (Exception e) {            Log.e("UnRegister Receiver Error","> " + e.getMessage());        }    }    @OverrIDe    public voID onBackpressed() {        super.onBackpressed();    }    @OverrIDe    protected voID onResume() {        super.onResume();        Log.e(TAG,"in onResume in mainactivity");    }    @OverrIDe    public file getCacheDir()    {        // NOTE: this method is used in AndroID 2.1Log.e(TAG,"getcachedir");        return getApplicationContext().getCacheDir();    }    @OverrIDe    protected voID onSaveInstanceState(Bundle outState)    {        super.onSaveInstanceState(outState);        // Save the state of the WebVIEw        webVIEw.saveState(outState);    }    @OverrIDe    protected voID onRestoreInstanceState(Bundle savedInstanceState)    {        super.onRestoreInstanceState(savedInstanceState);        // Restore the state of the WebVIEw        webVIEw.restoreState(savedInstanceState);    }}

.

这是上面教程中写入sdcard的代码.

package com.bmi.bmitestapp;import java.io.file;import androID.app.Application;import androID.os.Environment;import androID.util.Log;public class ApplicationExt extends Application{    private static final String TAG = ApplicationExt.class.getSimplename();    // NOTE: the content of this path will be deleted    //       when the application is uninstalled (AndroID 2.2 and higher)    protected file extStorageAppBasePath;    protected file extStorageAppCachePath;    @OverrIDe    public voID onCreate()    {        super.onCreate();         Log.e(TAG,"insIDe appext");        // Check if the external storage is writeable        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))        {            // RetrIEve the base path for the application in the external storage            file externalStorageDir = Environment.getExternalStorageDirectory();            if (externalStorageDir != null)            {                // {SD_PATH}/AndroID/data/com.devahead.androIDwebvIEwcacheonsd                extStorageAppBasePath = new file(externalStorageDir.getabsolutePath() +                    file.separator + "AndroID" + file.separator + "data" +                    file.separator + getPackagename());            }            if (extStorageAppBasePath != null)            {                // {SD_PATH}/AndroID/data/com.devahead.androIDwebvIEwcacheonsd/cache                extStorageAppCachePath = new file(extStorageAppBasePath.getabsolutePath() +                    file.separator + "cache");                boolean isCachePathAvailable = true;                if (!extStorageAppCachePath.exists())                {                    // Create the cache path on the external storage                    isCachePathAvailable = extStorageAppCachePath.mkdirs();                }                if (!isCachePathAvailable)                {                    // Unable to create the cache path                    extStorageAppCachePath = null;                }            }        }    }    @OverrIDe    public file getCacheDir()    {        // NOTE: this method is used in AndroID 2.2 and higher        if (extStorageAppCachePath != null)        {            // Use the external storage for the cache            Log.e(TAG,"extStorageAppCachePath = " + extStorageAppCachePath);            return extStorageAppCachePath;        }        else        {            // /data/data/com.devahead.androIDwebvIEwcacheonsd/cache            return super.getCacheDir();        }    }}

我以为我会包括一点点伐木.这是在网络适配器打开的情况下从全新安装进行的日志记录.

01-29 14:13:10.220: D/dalvikvm(16904): Late-enabling CheckJNI01-29 14:13:10.470: E/ApplicationExt(16904): insIDe appext01-29 14:13:10.720: E/Registeractivity(16904): in onresume in registeractivity01-29 14:13:10.880: D/libEGL(16904): loaded /system/lib/egl/libEGL_tegra.so01-29 14:13:11.000: D/libEGL(16904): loaded /system/lib/egl/libGLESv1_CM_tegra.so01-29 14:13:11.030: D/libEGL(16904): loaded /system/lib/egl/libGLESv2_tegra.so01-29 14:13:11.070: D/Openglrenderer(16904): Enabling deBUG mode 001-29 14:13:18.390: E/ApplicationExt(16904): extStorageAppCachePath = /mnt/sdcard/AndroID/data/com.bmi.bmitestapp/cache01-29 14:13:18.390: D/webvIEw(16904): [InitTabEffectPivot] >> nScreenWIDth = 72001-29 14:13:18.390: D/webvIEw(16904): [InitTabEffectPivot] >> nScreenHeight = 128001-29 14:13:18.390: D/sqliteDatabaseCpp(16904): Registering sqlite logging func: /data/data/com.bmi.bmitestapp/databases/webvIEw.db01-29 14:13:18.390: D/sqliteDatabaseCpp(16904): DB info: open db,path = /data/data/com.bmi.bmitestapp/databases,key = sefraes,flag = 6,cannot stat file,errno = 2,message = No such file or directory01-29 14:13:18.400: E/MainActivity(16904): in onCreate in mainactivity01-29 14:13:18.400: D/sqliteDatabaseCpp(16904): DB info: path = /data/data/com.bmi.bmitestapp/databases,handle: 0x1f9a858,type: w,r/w: (0,1),mode: delete,disk free size: 1276 M01-29 14:13:18.400: D/GCMRegistrar(16904): @R_419_5990@ting backoff for com.bmi.bmitestapp01-29 14:13:18.420: V/GCMRegistrar(16904): Registering app com.bmi.bmitestapp of senders 59808074459301-29 14:13:18.430: E/ApplicationExt(16904): extStorageAppCachePath = /mnt/sdcard/AndroID/data/com.bmi.bmitestapp/cache01-29 14:13:18.430: E/MainActivity(16904): appCachePath = /mnt/sdcard/AndroID/data/com.bmi.bmitestapp/cache01-29 14:13:18.430: E/MainActivity(16904): we have a network connection01-29 14:13:18.430: E/MainActivity(16904): in onResume in mainactivity01-29 14:13:18.490: W/webcore(16904): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebVIEwCore is set up.01-29 14:13:18.490: W/webcore(16904):   at androID.webkit.WebVIEwCore$EventHub.removeMessages(WebVIEwCore.java:1974)01-29 14:13:18.490: W/webcore(16904):   at androID.webkit.WebVIEwCore$EventHub.access00(WebVIEwCore.java:1008)01-29 14:13:18.490: W/webcore(16904):   at androID.webkit.WebVIEwCore.removeMessages(WebVIEwCore.java:2215)01-29 14:13:18.490: W/webcore(16904):   at androID.webkit.WebVIEw.sendOurVisibleRect(WebVIEw.java:3285)01-29 14:13:18.490: W/webcore(16904):   at androID.webkit.ZoomManager.setZoomScale(ZoomManager.java:772)01-29 14:13:18.490: W/webcore(16904):   at androID.webkit.ZoomManager.access00(ZoomManager.java:59)01-29 14:13:18.490: W/webcore(16904):   at androID.webkit.ZoomManager$postscale.run(ZoomManager.java:1345)01-29 14:13:18.490: W/webcore(16904):   at androID.os.Handler.handleCallback(Handler.java:608)01-29 14:13:18.490: W/webcore(16904):   at androID.os.Handler.dispatchMessage(Handler.java:92)01-29 14:13:18.490: W/webcore(16904):   at androID.os.Looper.loop(Looper.java:156)01-29 14:13:18.490: W/webcore(16904):   at androID.app.ActivityThread.main(ActivityThread.java:5045)01-29 14:13:18.490: W/webcore(16904):   at java.lang.reflect.Method.invokeNative(Native Method)01-29 14:13:18.490: W/webcore(16904):   at java.lang.reflect.Method.invoke(Method.java:511)01-29 14:13:18.490: W/webcore(16904):   at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)01-29 14:13:18.490: W/webcore(16904):   at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551)01-29 14:13:18.490: W/webcore(16904):   at dalvik.system.NativeStart.main(Native Method)01-29 14:13:18.500: W/webcore(16904): java.lang.Throwable: EventHub.removeMessages(int what = 105) is not supported before the WebVIEwCore is set up.01-29 14:13:18.500: W/webcore(16904):   at androID.webkit.WebVIEwCore$EventHub.removeMessages(WebVIEwCore.java:1974)01-29 14:13:18.500: W/webcore(16904):   at androID.webkit.WebVIEwCore$EventHub.access00(WebVIEwCore.java:1008)01-29 14:13:18.500: W/webcore(16904):   at androID.webkit.WebVIEwCore.removeMessages(WebVIEwCore.java:2215)01-29 14:13:18.500: W/webcore(16904):   at androID.webkit.WebVIEw.sendVIEwSizeZoom(WebVIEw.java:3520)01-29 14:13:18.500: W/webcore(16904):   at androID.webkit.ZoomManager.setZoomScale(ZoomManager.java:778)01-29 14:13:18.500: W/webcore(16904):   at androID.webkit.ZoomManager.access00(ZoomManager.java:59)01-29 14:13:18.500: W/webcore(16904):   at androID.webkit.ZoomManager$postscale.run(ZoomManager.java:1345)01-29 14:13:18.500: W/webcore(16904):   at androID.os.Handler.handleCallback(Handler.java:608)01-29 14:13:18.500: W/webcore(16904):   at androID.os.Handler.dispatchMessage(Handler.java:92)01-29 14:13:18.500: W/webcore(16904):   at androID.os.Looper.loop(Looper.java:156)01-29 14:13:18.500: W/webcore(16904):   at androID.app.ActivityThread.main(ActivityThread.java:5045)01-29 14:13:18.500: W/webcore(16904):   at java.lang.reflect.Method.invokeNative(Native Method)01-29 14:13:18.500: W/webcore(16904):   at java.lang.reflect.Method.invoke(Method.java:511)01-29 14:13:18.500: W/webcore(16904):   at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)01-29 14:13:18.500: W/webcore(16904):   at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551)01-29 14:13:18.500: W/webcore(16904):   at dalvik.system.NativeStart.main(Native Method)01-29 14:13:18.530: D/Openglrenderer(16904): Flushing caches (mode 0)01-29 14:13:18.570: I/sqliteDatabaseCpp(16904): sqlite returned: error code = 1,msg = no such table: CacheGroups01-29 14:13:18.570: I/sqliteDatabaseCpp(16904): sqlite returned: error code = 1,msg = no such table: Caches01-29 14:13:18.570: I/sqliteDatabaseCpp(16904): sqlite returned: error code = 1,msg = no such table: Origins01-29 14:13:18.570: I/sqliteDatabaseCpp(16904): sqlite returned: error code = 1,msg = no such table: DeletedCacheResources01-29 14:13:18.850: E/ApplicationExt(16904): extStorageAppCachePath = /mnt/sdcard/AndroID/data/com.bmi.bmitestapp/cache01-29 14:13:19.330: I/PRIME(16904): <CallBackProxy> Send to WebVIEwClIEnt.01-29 14:13:19.370: V/GCMbroadcastReceiver(16904): onReceive: com.Google.androID.c2dm.intent.REGISTRATION01-29 14:13:19.370: V/GCMbroadcastReceiver(16904): GCM IntentService class: com.bmi.bmitestapp.GCMIntentService01-29 14:13:19.370: V/GCMBaseIntentService(16904): Acquiring wakelock01-29 14:13:19.460: V/GCMBaseIntentService(16904): Intent service name: GCMIntentService-598080744593-101-29 14:13:19.470: E/GCMRegistrar(16904): internal error: retry receiver class not set yet01-29 14:13:19.480: V/GCMRegistrar(16904): Registering receiver01-29 14:13:19.480: D/GCMBaseIntentService(16904): handleRegistration: registrationID = APA91bFytZvnkmsEVHSnw5VRxIwfPRmPsSRVrgRNRa5ww3oqCfnLEZMaBBNtQtlZoK4RD4VQXfAfKDsQUa53PwQBH_rwuI_gEEdHQhxadpBVmJ7L3Dxy90Bzryg_aCWx20-cdZ32cbiiaGR3zUMjpqZizYQbnARN4w,error = null,unregistered = null01-29 14:13:19.480: D/GCMRegistrar(16904): @R_419_5990@ting backoff for com.bmi.bmitestapp01-29 14:13:19.480: V/GCMRegistrar(16904): Saving regID on app version 101-29 14:13:19.490: I/GCMIntentService(16904): Device registered: regID = APA91bFytZvnkmsEVHSnw5VRxIwfPRmPsSRVrgRNRa5ww3oqCfnLEZMaBBNtQtlZoK4RD4VQXfAfKDsQUa53PwQBH_rwuI_gEEdHQhxadpBVmJ7L3Dxy90Bzryg_aCWx20-cdZ32cbiiaGR3zUMjpqZizYQbnARN4w01-29 14:13:19.490: D/name(16904): hardcoded clIEnt name01-29 14:13:19.490: I/bmi GCM(16904): registering device (regID = APA91bFytZvnkmsEVHSnw5VRxIwfPRmPsSRVrgRNRa5ww3oqCfnLEZMaBBNtQtlZoK4RD4VQXfAfKDsQUa53PwQBH_rwuI_gEEdHQhxadpBVmJ7L3Dxy90Bzryg_aCWx20-cdZ32cbiiaGR3zUMjpqZizYQbnARN4w)01-29 14:13:19.490: D/bmi GCM(16904): Attempt #1 to register01-29 14:13:19.500: V/bmi GCM(16904): Posting 'email=hardcoded email&regID=APA91bFytZvnkmsEVHSnw5VRxIwfPRmPsSRVrgRNRa5ww3oqCfnLEZMaBBNtQtlZoK4RD4VQXfAfKDsQUa53PwQBH_rwuI_gEEdHQhxadpBVmJ7L3Dxy90Bzryg_aCWx20-cdZ32cbiiaGR3zUMjpqZizYQbnARN4w&name=hardcoded clIEnt name' to http://mobilewebexpert.co.uk/pushtest/register.PHP01-29 14:13:19.500: E/URL(16904): > http://mobilewebexpert.co.uk/pushtest/register.PHP01-29 14:13:20.610: V/GCMRegistrar(16904): Setting registeredOnServer status as true until 2013-02-05 14:13:20.61701-29 14:13:20.620: V/GCMBaseIntentService(16904): Releasing wakelock01-29 14:13:21.470: D/skia(16904): notifyPluginsOnFrameLoad not postponed01-29 14:13:21.570: D/sqliteDatabase(16904): Create pool connection01-29 14:13:21.570: D/sqliteDatabaseCpp(16904): DB info: open db,flag = 1,file size = 1228801-29 14:13:21.570: D/sqliteDatabaseCpp(16904): DB info: path = /data/data/com.bmi.bmitestapp/databases,handle: 0x2797350,type: r,r/w: (1,mode: wal,disk free size: 1276 M

.

这是我关闭网络适配器后的日志记录.

01-29 14:16:57.080: E/Registeractivity(16904): in onresume in registeractivity01-29 14:17:03.490: D/webvIEw(16904): [InitTabEffectPivot] >> nScreenWIDth = 72001-29 14:17:03.490: D/webvIEw(16904): [InitTabEffectPivot] >> nScreenHeight = 128001-29 14:17:03.490: E/MainActivity(16904): in onCreate in mainactivity01-29 14:17:03.490: V/GCMRegistrar(16904): Is registered on server: true01-29 14:17:03.500: E/ApplicationExt(16904): extStorageAppCachePath = /mnt/sdcard/AndroID/data/com.bmi.bmitestapp/cache01-29 14:17:03.500: E/MainActivity(16904): appCachePath = /mnt/sdcard/AndroID/data/com.bmi.bmitestapp/cache01-29 14:17:03.500: E/MainActivity(16904): we don't have a network connection01-29 14:17:03.500: E/MainActivity(16904): in onResume in mainactivity01-29 14:17:03.500: D/chromium(16904): UnkNown chromium error: -40001-29 14:17:03.540: D/skia(16904): notifyPluginsOnFrameLoad not postponed01-29 14:17:03.580: D/Openglrenderer(16904): Flushing caches (mode 0)

有一点我注意到,它可能没什么,但注册性是指调用MainActivity的活动. Registeractivity只有一个按钮,可以触发MainActivity的Intent.网络适​​配器关闭后,我必须按下registeracivity上的按钮,该按钮调用MainActivity中的onCreate.它就像是一个MainActivity的新实例?这可能会影响webvIEw的缓存.实际上,必须在此过程中调用主要活动的onDestroy.

另一件事引起了我的注意.

01-29 14:17:03.580: D/Openglrenderer(16904): Flushing caches (mode 0)
解决方法 对于该特定URL http://bmi.cubecore.co.uk,该http服务器禁止您的WebVIEw缓存,请参阅响应头Cache-Control:
200 OK... ...Pragma: no-cacheServer: Apache/2.2.3 (CentOS)Content-Type: text/HTML; charset=utf-8Cache-Control: no-store,no-cache,must-revalIDate,post-check=0,pre-check=0Expires: Thu,19 Nov 1981 08:52:00 GMT

这意味着客户端必须始终从http服务器连接并加载URL,而不是从其本地缓存加载.这也解释了为什么在网络适配器关闭后尝试加载页面时出现未知铬错误:-400.未知的铬错误:-400通常意味着由于某种原因无法连接互联网.

没有登录就无法做任何事情并调整http服务器设置.您可以使用以下URL检查缓存实现:

https://stackoverflow.com/questions/14549638/webvIEw-not-displaying-website-when-offline

响应标头是:

200 OK... ...Last-ModifIEd: Wed,30 Jan 2013 00:28:59 GMTvary: *Content-Type: text/HTML; charset=utf-8Cache-Control: public,max-age=60Expires: Wed,30 Jan 2013 00:29:59 GMT

如果代码中没有其他问题,则缓存实现应该可行.

总结

以上是内存溢出为你收集整理的android – webView在离线时不显示网站全部内容,希望文章能够帮你解决android – webView在离线时不显示网站所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1148904.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存