Opening WebView in the background

This is the first time I ask something, so if something is wrong, just tell me and I will try to fix it as soon as possible.

We have a client who wants us to access our servers using our own Android application, but we don’t provide us with our own way to do this. They want us to use the current website, which they must register, and after authentication, retrieve the XML in the browser that contains the data we need. After that, use the data in the native application. All this when the user does not know / sees that the browser is being used. Complete mess IMHO.

Of course, I have never tried this approach in the past, and my first tests make me feel that this is impossible (or extremely difficult) to achieve. Whenever I try to load a URL in a hidden web browser, the default browser pops up showing the website.

My main question is: is it possible to download a web view and work with it (call javascript, etc.) in the background?

Thanks.

+6
source share
2 answers

You can set the WebView to the default hidden attribute android: visibility = "gone", interact with it at runtime, and then when you need to show it to the user after loading the data, just call setVisibility (View.Visible)

Hope this helps!

+7
source

Ofc, you should use Thread:

protected void getPage(){ Thread th = new Thread(){ public void run(){ //Download and make things mActivity.runOnUiThread(new Runnable() { @Override public void run() { //print int the activity } }); } }; th.start(); 

Remember that this is VERY important, you cannot draw a thread from the main activity. The only one who can draw on the screen is the main activity. You can draw in two ways:

One, with the _mActivity.runOnUiThread method (new Runnable () {_ as the example I set. Two, use a handler to send messages from the stream to the main action with the information you want to draw.

* The main action is the action that is on the screen at that moment, and not the first activity of the application

+1
source

Source: https://habr.com/ru/post/895577/


All Articles