在Android服务中使用WebView.findAll()
我对我的在Android服务中使用WebView.findAll(),android,service,webview,Android,Service,Webview,我对我的服务进行了如下编程: public int onStartCommand(Intent intent, int flags, int startId) { loadVariables(); webview = new WebView(this); webview.loadUrl(url); makeNotification = notificationMaker(); result = webview.findAll(part1) > 0;
服务进行了如下编程:
public int onStartCommand(Intent intent, int flags, int startId) {
loadVariables();
webview = new WebView(this);
webview.loadUrl(url);
makeNotification = notificationMaker();
result = webview.findAll(part1) > 0;
if (result == true){
notification();
}
return super.onStartCommand(intent, flags, startId);
}
我想启动它,检查是否在webview
中找到字符串part1,并发出通知,但它什么也不做
第1部分和url加载正确,通知也能正常工作(我通过在toast中打印它们来检查),因此webview
一定有问题
是否需要在XML文件中显示它,如果需要,我认为它对服务不起作用,对吗?webView.loadUrl是异步的。但在我的主类中,它在正常运行应用程序时工作,如果我在第6行插入==而不是>,它将返回一个通知。webView不会在服务中加载。它们必须仅在活动中使用如果您插入==而不是>,您将测试findAll是否未找到任何内容,这可能是因为尚未加载任何内容。如果没有,您是如何在服务中使用WebView的?你确定这样行吗?