• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Communication between Service and Activity

Kians

Lurker
Hi,

I open a new thread to talk about my problem :-) , I have problems with communication between "service" to the "Activity"

what I have:
I have a FTP download of a file that is downloaded in the background as a service! In the end I had a time X in a variable.
furthermore it is checked whether the file is also fully load , I make it with a simple comparison of the data size.


So I have a time 0s "start time" 12:22:00 up as 20sec is "end time" 12:22:20
and a download size of 0Kb goes to 5000kb.

These values are defined in the service.


Project:

I want to show this graphically or via text in the GUI of the activity .

like this:

File Download time: X seconds
X seconds, will be scanned progressively and dynamically displayed. 1. sec, 2 sec ...... 20 sec

Download traffic: X kb of 5000 kb

Download rate is to be displayed: 0kb, 250 kb, 500 kb ..... 5000 kb.




Now my question:

how do I do that, which transfers the service these values to the activity!
and how can I display in the activity "dynamically and automatically."




I thank you all for your efforts
 
You can use a BroadcastReceiver for this. Have your service send an Intent of a specific type. You can add whatever values you need in the Intent's bundle. Then send it via context.sendBroadcast(your Intent).

Set up a BroadcastReceiver in your Activity for that specific type of Intent and then read the values from the intent bundle.

BroadcastReceiver | Android Developers
 
Back
Top Bottom