Passing a Javascript Variable to Android Activity?

前端 未结 3 1796
情歌与酒
情歌与酒 2020-12-21 19:00

Basically I want get data I already have accessed from javascript and passing it to Java/Android so that I can work with it there.

     /* An instance of thi         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 19:04

    I think it will be a good idea to store the HTML in Shared Preferences ,which is a form of persistent storage.This way you will be able to access it from anywhere.

       //------get sharedPreferences
    
    SharedPreferences pref = context.getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE);
    
    //--------modify the value
    
    pref.edit().putString("ToastString", html).commit();
    
    //-------get a value from this from anywhere
    
    String toastValue=pref.getString("ToastString", "");
    

提交回复
热议问题