简体   繁体   中英

Local Storage in Android Web View doesn't work sometimes

I use a local storage variable in a HTML5/Javascript game to store the highscore of the game. This is working great without any problems. But when I wrap the game in a Web View in an Android App there are sometimes problems.

So the Highscore is saved in local storage but sometimes when I close the app and start it again, the highscore got reset. But sometimes the highscore is still there?!

For example: I start the game, make a highscore, close the app, start it again, the highscore is lost, I close the app, start it again, the highscore is still lost, I close it, start it again and then the highscore is there.

The code in Java:

    webSettings.setJavaScriptEnabled(true);
    webSettings.setDatabaseEnabled(true);
    mywebview.getSettings().setDatabasePath("/data/data/" + mywebview.getContext().getPackageName() + "/databases/");
    webSettings.setDomStorageEnabled(true);

Any ideas, what is causing the problems?

I use now SharedPreferences as a workaround to store my highscores via a Javascript Interface. This is working great.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM