Android: Using WebView outside an Activity context

前端 未结 10 2027
执念已碎
执念已碎 2020-11-27 03:20

I am trying to achieve Web Scraping through a background IntentService that periodically scrape a website without a view displaying on the users phone.

  • Since
10条回答
  •  北海茫月
    2020-11-27 04:11

    the solution was like this, but with Looper.getMainLooper() :

    https://github.com/JonasCz/save-for-offline/blob/master/app/src/main/java/jonas/tool/saveForOffline/ScreenshotService.java

    @Override
    public void onCreate() {
        super.onCreate();
        //HandlerThread thread = new HandlerThread("ScreenshotService", Process.THREAD_PRIORITY_BACKGROUND);
        //thread.start();
        //mServiceHandler = new ServiceHandler(thread.getLooper()); // not working
        mServiceHandler = new ServiceHandler(Looper.getMainLooper()); // working
    }
    

    with help of @JonasCz : https://stackoverflow.com/a/28234761/466363

提交回复
热议问题