1. Are you ready for the Galaxy S20? Here is everything we know so far!

Updating main activity from a service and general questions

Discussion in 'Android Lounge' started by amankhalid, Aug 30, 2018.

  1. amankhalid

    amankhalid Newbie
    Thread Starter

    Hi,

    I am new to Android. I am designing an app that pulls prices of commodities from a website and inform the user when the price changes. I am targeting Android API 19, but I own a Pixel 2 running Android P (so I test in an AVD as well as on the phone).

    I have a service that is registered with the AlarmManager such that it is run periodically. That service performs HTTP get operation to fetch the data. The service is a class of its own. I have a few questions to ask to firm my understanding:

    1. I want the service to start when the device is restarted as well as when the app is re-installed / updated. I created a broadcast receiver that listens for boot complete. I've seen that boot complete takes a long time to occur (as I can see with toasts and logcat).

    a) How do I ensure the service is registered with the AlarmManager when the app is updated or reinstalled?

    b) Is there a way to know that the service has already been registered with the AlarmManager?

    2. I want to pass the data from service to the main activity without launching it. The service may not know about previous price so it can't decide if the price has changed. My main activity is already extending a class, so I can't extend Broadcast Receiver. I want to be able to display the changed prices in the main activity, only when it is launched. How do I go about it? If there is a better approach, please do suggest.

    Regards
    AK
     


Loading...

Share This Page

Loading...