Android Question Confused: Please clarify class/service.

Mark Read

Well-Known Member
Licensed User
Longtime User
In my app I have only the activity "Main". There are quite a few subroutines. I would like to take some of them out to make the coding easier to read. The subs I want to take out would then make something similar to a service I think.

My idea would be to pass two parameters to this "service", allow the "service" to run, calculate and insert its results into a global list-variable in "Main".

My understanding is that there can be no interaction from the service with the activity whilst running. This is a problem, as this "Service" needs to interact with a webview (which is currently hidden in "Main"). No view is seen when the "service" runs but I would like the main-activity to be visible at all times. Theoretically I can move the subs to a second activity but there is nothing I want the user to see and then main is not visible.

The function of the "service" would be:

1. create an URL
2. Send URL to a website (which is running javascript)
3. Wait for webpage_loaded. Start a timer and wait for the website to finish calculations.
4. Get the data from the website.
5. Collect data from website and give data back to Main.

The website is not mine, I am injecting javascript into the webview to control the different function.

I hope this is clear.

I have read everything I can find but am still confused. Can someone point me in the right direction?

Many thanks.
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
I don't think a Service is for what you are looking. Try a static code module.

If all you're worried about is the ease with which you can maintain your code, then I suggest keeping all your subs in the Main module and just grouping them together as you see fit into collapsible #Regions. This will make your navigation through the Main module much easier.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
I suggest keeping all your subs in the Main module and just grouping them together as you see fit into collapsible #Regions

This is exactly what I have at present. I have a bare-bones Main at present and would like to extend it with all features. Thats why I wanted to move parts out into a stand alone "service" or code module.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Another thought, if I move the "generate URL and load in webview" sub to a module, will the WebView1_PageFinished (Url As String) sub execute when it is also in the code module?
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
It will execute in whatever module WebView1 was declared. WebViews (like all Views) are Activity Objects, accessible only in their Activity. You can, of course, pass a WebView as an argument to a method in a code module and then that method can manipulate that WebView. But the event should be in the Activity.
 
Upvote 0
Top