Android: Using WebView outside an Activity context

前端 未结 10 2141
执念已碎
执念已碎 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:03

    I used the following code to get round this problem:

    Handler handler = new Handler(Looper.getMainLooper());
    try
    {
        handler.post(
            new Runnable()
            {
                @Override
                public void run()
                {
                    ProcessRequest(); // Where this method runs the code you're needing
                }
            }
        );
    } catch (Exception e)
    {
        e.printStackTrace();
    }
    

提交回复
热议问题