Android: Using WebView outside an Activity context

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

    Correct me if I am wrong but the correct answer to this question is that there is NO possible way to use a WebView in the background while the user is doing other things on the phone without interrupting the user by means of an Activity.

    I have applied both Randy and Code_Yoga's suggestions: Using an activity with "Theme.NoDisplay" to launch a background service with a WebView to do some work. However even though no view is visible the switching to that activity for that second to start the services interrupts the user (ex. like pausing a running game that was being played).

    Totally disastrous news for my app so I am still hoping someone will give me a way to use a WebView that does not need an Activity (or a substitute for a WebView that can accomplish the same)

    0 讨论(0)
  • 2020-11-27 04:12

    You can use this to hide the Activity

             <activity android:name="MyActivity"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoDisplay">
    

    Doing this will prevent the app from showing any Activity. And then you can do your stuff in the Activity.

    0 讨论(0)
  • 2020-11-27 04:12

    or a substitute for a WebView that can accomplish the same <=== if you do not wish to show the loaded info on UI, maybe you can try to use HTTP to call the url directly, and process on the returned response from HTTP

    0 讨论(0)
  • 2020-11-27 04:17

    I know it'a been a year and a half, but I'm now facing the same issue. I solved it eventually by running my Javascript code inside a Node engine that is running inside my Android App. It's called JXCore. You can take a look. Also, take a look at this sample that runs Javascript without a WebView. I really would like to know what did you end up using?

    0 讨论(0)
提交回复
热议问题