Thursday, July 21, 2011

Re: [android-developers] How to get a service to either return a string or start a function in main activity?

Thank you for your prompt reply,
What I am writing is a meds reminder app, which has the option of
letting a career know if the app is not acknowledged and responded to.

The idea is that when the alarm event fires it triggered a sound
(alert) to be played (notify user to take meds), and if the alert is
not cancelled inside of a given time, then an sms is sent to inform
the carer.

I have most of the code nicely nailed down, except spawning a screen
or alert dialogue which has the Cancel button on it, and it is with
this matter that I seek help.

As you note in your reply, it is how to Bind the code from the
.alarmservice to trigger the alert dialogue or screen in which I am
lacking understanding and would hugely appreciate assistance.

Regards,
Fred

On 21/07/2011, Mark Murphy <mmurphy@commonsware.com> wrote:
> On Thu, Jul 21, 2011 at 4:25 PM, Fred Niggle <fred.niggle@googlemail.com>
> wrote:
>> however, my goal is to start a service which sets an alarm, and when
>> the alarm fires the onStart() event I wish to display another screen
>> (e.g. anothermain.xml)
>
> That's a trifle unusual. It would make sense, as a user-chosen option,
> if the app is an alarm clock. Generally, services should not be
> starting activities, since you don't know what the user is doing at
> the time, and the user may not appreciate the interruption.
>
>> In another of the tutorials I found there is a secction at the foot
>> of the service class which defines an interface:
>>
>> public interface HardButtonListener {
>> void onPrevButtonPress();
>> void onNextButtonPress();
>> void onPlayPauseButtonPress();
>> }
>>
>> So it seems to me that the service can 'fire' either of the events
>> back in the activity, but how do I go about setting this up (the more
>> i google the more confused i become)?
>
> The way you would do that is via the binding pattern, which is not
> available to you if you are using AlarmManager. Again, if you are
> using AlarmManager, you have no idea whether your activity even
> exists, let alone is in the foreground.
>
> You may get more help if you explain what it is that you are trying to
> build.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> _Android Programming Tutorials_ Version 3.5 Available!
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment