Yes, that is a standard pattern. On Tue, Jan 13, 2009 at 2:02 PM, Sarath Kamisetty < [email protected]> wrote:
> > Are you suggesting that I should use startService() itself as a > notification to the service ? I guess I can override onStart() method > which is called everytime startService() is called to do the job. Let > me try this approach and see if it works. > > Thanks, > Sarath > > On Tue, Jan 13, 2009 at 12:56 PM, Sarath Kamisetty > <[email protected]> wrote: > > I did that and the service starts (I can see the log message from > > onCreate() method) but i want to know how to let the service know that > > activity updated data from that point onwards ? Isn't there any other > > way other than AIDL ? > > > > On Tue, Jan 13, 2009 at 12:25 PM, Dianne Hackborn <[email protected]> > wrote: > >> Call startService() like the API demo does. There is a sample showing > >> exactly this kind of thing. > >> > >> On Tue, Jan 13, 2009 at 12:03 PM, Sarath Kamisetty > >> <[email protected]> wrote: > >>> > >>> Hi, > >>> > >>> I looked at the other thread where running service in a separate > >>> process by itself is discouraged and considered rare. In my case, my > >>> activity and the service both use SQLite so I don't expect to see > >>> synchronization issues. So, how do I bring my service to life from the > >>> activity, let it process new information, and put itself to sleep > >>> until a specific time (which could change every time) or by another > >>> notification by the activity ? Can I use broadcast intent/receiver > >>> here ? With the intents, invoking service seems to be easy. All my > >>> activity needs to tell the service is that some information is updated > >>> (service knows where to look for this information). If the service is > >>> not running, it should be started, if it is scheduled to run in future > >>> (through AlarmManager) that should be canceled and rescheduled using > >>> new timer value calculated after processing the information. > >>> > >>> I am thinking of the following: > >>> > >>> activity activates services by doing the following: > >>> > >>> Intent intent = new Intent(this, myservice.class); > >>> this.sendBroadcast(intent); > >>> > >>> In the service, I create a task that runs a thread at some point in > >>> future. When the service is notified of this intent, I will check if a > >>> thread is scheduled to run and if so, I want to cancel the scheduled > >>> task. Then I will process new information and then re-schedule a new > >>> task, if needed. Does this sound like a good approach ? With this I > >>> don't seem to require any aidl. > >>> > >>> Thanks, > >>> Sarath > >>> > >>> On Mon, Jan 12, 2009 at 3:59 PM, Dianne Hackborn <[email protected]> > >>> wrote: > >>> > Yes, all of the components of your app share data in the same place > of > >>> > the > >>> > filesystem, regardless of the process they run in, so any changes you > >>> > make > >>> > there will be seen by all of them. Of course you have to be careful > if > >>> > you > >>> > have multiple processes modifying the same file that they don't step > on > >>> > each > >>> > other. SQLite takes cares of this for you. > >>> > > >>> > See, however, my previous e-mail; from your description this doesn't > >>> > sound > >>> > like a case where having a service in a separate process is > necessarily > >>> > a > >>> > good idea. > >>> > > >>> > And yes, using bindService() (with the appropriate flag passed in) > will > >>> > have > >>> > the service running as long as that client is bound to it. > >>> > > >>> > On Mon, Jan 12, 2009 at 12:49 PM, Sarath Kamisetty > >>> > <[email protected]> wrote: > >>> >> > >>> >> Hi, > >>> >> > >>> >> I am a little bit confused about what can/cannot a service access > when > >>> >> it is running as an independent process (remote service). I have a > >>> >> database created by my activity when it is run the 1st time. Later > on > >>> >> this activity adds entries to this database. I don't want my service > >>> >> running all the time, instead the service uses AlarmManager to > >>> >> schedule itself to run (sometimes it doesn't know when to run, so > has > >>> >> to suspend itself forever until notified by the activity). For > >>> >> activity to service communication aidl will be used, but I was > >>> >> wondering if the service, if run as independent process, can access > >>> >> the database created and updated by the activity ? Can an > application > >>> >> have multiple processes ? If so, I guess as long as the service and > >>> >> activity belong to same application I think the answer is yes, but > can > >>> >> someone please confirm ? or is there a need in this case to have > >>> >> activity and service in completely different applicaitons accessing > >>> >> shared database (don't know if this is possible) ? > >>> >> > >>> >> The other help I am looking for is, in this case how should my > >>> >> activity be invoking the service ? If I use bindService() will that > >>> >> make service run when the activity is running (something I don't > >>> >> need/want to happen) ? or do I need to use some intent and let the > >>> >> system notify my service ? Can anyone suggest how to design this ? > >>> >> > >>> >> Thanks, > >>> >> Sarath > >>> >> > >>> >> > >>> > > >>> > > >>> > > >>> > -- > >>> > Dianne Hackborn > >>> > Android framework engineer > >>> > [email protected] > >>> > > >>> > Note: please don't send private questions to me, as I don't have time > to > >>> > provide private support. All such questions should be posted on > public > >>> > forums, where I and others can see and answer them. > >>> > > >>> > > >>> > > > >>> > > >>> > >>> > >> > >> > >> > >> -- > >> Dianne Hackborn > >> Android framework engineer > >> [email protected] > >> > >> Note: please don't send private questions to me, as I don't have time to > >> provide private support. All such questions should be posted on public > >> forums, where I and others can see and answer them. > >> > >> > >> >> > >> > > > > > > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

