1. Check out our companion app, Forums for Android! Download from Google Play

Communication between Service and Activity

Discussion in 'Application Development' started by Kians, Sep 30, 2010.

  1. Kians

    Kians New Member
    Thread Starter
    5

    Sep 30, 2010
    1
    0
    5
    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
     

    Advertisement

  2. RNekic

    RNekic Member
    16

    May 25, 2010
    12
    1
    16
    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
     

Share This Page

Loading...