如何计算多个 Android WebView 所需的总时间?

how to calculate total time taken for multiple android webview?

提问人:MOHAMED SIKKANDAR AFZAL M 提问时间:9/10/2021 更新时间:12/24/2021 访问量:38

问:

我已经在Android中加载了多个WebView,我知道WebView加载所需的时间是“onPageStarted”和“onPageFinished”之间的差异。但是我有多个webview如何计算webview加载时间?

Android 网页视图

评论


答:

1赞 nias fathima 12/24/2021 #1
class PerfIDs
{
    public long time;
    public String url;
    PerfIDs(long time, String url)
    {
        this.time = time;
        this.url = url;
    }
    public Long getUrl(String url) {
        return time;
    }
};

ArrayList<PerfIDs> appPerformanceTime = new ArrayList<PerfIDs>();
long startTime;
long endTime;
long firststartTime;
long lastendTime;
boolean startHold = true;
public void onPageStarted(WebView view, String url, Bitmap favicon) {
  startTime = System.currentTimeMillis();
  if(startHold){
    firststartTime = startTime;
    startHold = false;
  }
  appPerformanceTime.add(new PerfIDs(startTime,url));
  super.onPageStarted(view, url, favicon);
}
public void onPageFinished(WebView view, String url) {
  lastendTime = endTime = System.currentTimeMillis();
  int lastIndex = 0;
  for (int i = 0; i < appperftime.size(); i++) {
    String val = appperftime.get(i).url;
    if(url.equals(val)){
       System.out.println("url--"+url+"time-taken"+(endTime - appperftime.get(i).time));
       lastIndex = i;
     }
   }
if(lastIndex == appperftime.size()-1){
   System.out.println("total time taken --"+(lastendTime - firststartTime));
}
   super.onPageFinished(view, url);
}