Xamarin webview is able to refresh the screen with load url in Android 4 but not in Android 7

Balaji.1405Balaji.1405 USMember ✭✭

Can someone help how we can solve this issue . we have chasing up this issues from past 1 week but not able to resolve. Below code is working fine in Android 4 but in Android 7 when LoadUrl is called second time we are not able to see latest data it always shows old data. Please help

// Need to escape ' characters so the parameters strings
// aren't broken by a single quote inside the JSON values.
string jsonViewModel = JsonConvert.SerializeObject(newValue)
.Replace("\", "\\")
.Replace("'", "\'")
.Replace("\"", "\\"");

                // format the javascript command with the optional last paramter (templatePath)
                string jsCommand = string.Format(
                    "javascript:window.uibridge.DataBinding_updateValue('{0}','{1}','{2}'{3});",
                    uniqueID,
                    jsonViewModel,
                    (property ?? string.Empty),
                    (templatePath == null ? string.Empty : ",'" + templatePath + "'")
                    );

                Action loadURL = delegate()
                {

                    wv.LoadUrl(jsCommand);

                };

                if (wv.Context is Activity)
                {
                    // Android wants this call on the UI thread
                    ((Activity)wv.Context).RunOnUiThread(loadURL);
                }
                else
                {
                    // If the context is not an Activity, we can't
                    // jump to that thread easily.
                    loadURL.Invoke();
                }

Answers

  • Balaji.1405Balaji.1405 USMember ✭✭

    // Need to escape ' characters so the parameters strings
    // aren't broken by a single quote inside the JSON values.
    string jsonViewModel = JsonConvert.SerializeObject(newValue)
    .Replace("\", "\")
    .Replace("'", "\'")
    .Replace("\"", "\"");

                // format the javascript command with the optional last paramter (templatePath)
                string jsCommand = string.Format(
                    "javascript:window.uibridge.DataBinding_updateValue('{0}','{1}','{2}'{3});",
                    uniqueID,
                    jsonViewModel,
                    (property ?? string.Empty),
                    (templatePath == null ? string.Empty : ",'" + templatePath + "'")
                    );
    
                Action loadURL = delegate()
                {
    
                    wv.LoadUrl(jsCommand);
    
                };
    
                if (wv.Context is Activity)
                {
                    // Android wants this call on the UI thread
                    ((Activity)wv.Context).RunOnUiThread(loadURL);
                }
                else
                {
                    // If the context is not an Activity, we can't
                    // jump to that thread easily.
                    loadURL.Invoke();
                }
    
  • jezhjezh Member, Xamarin Team Xamurai
Sign In or Register to comment.