-1

I have an android app that created with html5+javascript in webview. In app exists a javascript variable with name high_score. I need to save this value with Sharedpreferences for use this value, anytime that user open the app.

Anyone knows how to do it?

user3616080
  • 31
  • 1
  • 1

1 Answers1

1

i don't know if you can get value from the javascript of your webview, but this link worth to try: How to get return value from javascript in webview of android?

after you get your value from js, you can save it on SharedPreferences

anyway SharedPreferences WILL NOT flushed when you closed your application

SharedPreferences WILL delete when you uninstall your application, or clear appplication data (or you manually delete in from your code)

how to save to sharedpreferences:

SharedPreferences prefs = this.getSharedPreferences("keyToAccessSH", Context.MODE_PRIVATE);
SharedPreferences.Editor ed = prefs.edit();
ed.putString("keyToAccessString", value);
ed.commit();

you can call this to get from sharedpreferences:

SharedPreferences prefs = this.getSharedPreferences("keyToAccessSH", Context.MODE_PRIVATE);
String get = prefs.getString("keyToAccessString", null);
//null is default value when keyToAccess not found

hope it's help

Community
  • 1
  • 1