Android Question Service?

ilan

Expert
Licensed User
Longtime User
hi

i cannot call one service in two different times right?
if i call a service at 17:00 and the same again at 17:05 it will perform at the last given time

is it possible to call one service at several times?

or how can i set for example 5 alarm times? do i need to create 5 services and call every one separately?
or is there a simpler way

thanx
 

DonManfred

Expert
Licensed User
Longtime User
If the service reaches the time it have to start. Do the work and then do a startserviceat and set the next time it have to run. You should use a list of timers with there starttimes or such... OR you use 5 services... but thats not a good idea i think.

You should use a list with timers (process_global) and find out the "next time a alarm must ring" and set startservicdeat to this time... On next alarm the time is reached and you look again in your list, when the next alarm have to ring...

On each run dont forget to set alarm1 to its new time

Something like this way

On the other side... Maybe explain in more details what you want to realize. Maybe the solution is simpler than described here...

For example: maybe you want a timer monday 8am, mo 3:30pm, fr 6am
And maybe you limit your "timedefinition" into minutes 0, 15, 30, 45. Or in 5 minute-steps...

You can easy do this. Set your service to start every 15 or 5 minutes (servicestartat 5 or 15 minutes in future).. The service will TICK. You check your list with wanted alerts and if the time fits then do the alert....
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
ok thanx i will explain exactly what i want to do

i have build a new app 4Tapz2

what the app does (in few words) you create a job with up to 4 actions like wifi on, gps off, ringer off
and give to this a job a tap code, now if you would like to perform those 3 actions you dont need to go to settings
and turn wifi on and then mute the phone and... (there are more complex actions) u just enter the app tap the tapcode and it will perform the actions now i would like to give the possibility to set for each job a schedule so the job will perform at given time

for example every night at 22:00 tunr wifi,gps,bluetooth off, mute the phone,...

the problem is the user define his jobs and i dont know hoe many jobs he will define thatswhy i cannot create endless service modules for each job he create

so what i need to do is create a list with all jobs that include a shedule and every time the user add a new job with a schedule it will add to the list and sort it by the time and also by day of the week, and when the service starts it will search for the next near job and startserviceat....

and when the user want to cancel a service he will just remove it from the list the service will run until the list is empty there the service will stop

or you have a better idea??

what will happen if the user will enter for 2 jobs the same starttime of the service and same day of the week?
the service will start only one job, or i will check if there is another job with the same starttime and perform immediately the next job

there is a very good app that u can set a lot of rules it calls AUTOMATIT
i am wondering how he solved this problem??

thanx
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Bitte, gern
In deutsch fällt die Antwort auch leichter. bzw in englisch ist es für mich schwerer eine antwort zu geben. Ich denke immer mein englisch sei grausam

Ich bleibe bei der Idee mit der Liste.... Vermutlich wäre sowas wie nen speziellen Type oder eine kleine SQLite db praktikabel... du musst ja nach jedem alert die neue zeit des aktiven alerts neu setzen. Ich würde, wie gesagt, vermutlich eine limitierung im 5 minutentakt machen. Dann hält sich die bateriebelastung in grenzen. Sticky service, alle 5 minuten...

Und wenn der service erst um 18:11 gestartet wird anstelle 18:10 dann solltest Du vielleicht noch eine karenzzeit von ner minute einbauen... Dann müsstest du aber normal den ansprüchen genügen denke ich.

Doppeltbelegungen musst du halt unterbinden einzutragen
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Danke ich werd dein Ratschalg befolgen aber nicht mit SQL weil ich kenn mich damit nicht aus

ich werd einfach ein liste bauen wo alle zeiten rein geschrieben werden und immer wenn ein service gestartet wird sucht er nach denn neachst furehesten service und startet dem

dass mit den 5 minuten takt ist eine gute Idee aber, aber vielleicht verstehe ich etwas am service nicht korrekt, der startet genau an dem Zeitpunkt den ich ihm gesagt habe oder?

kann es sein dass der service nicht an der eingegeben zeit gestartet wird?

danke

ps: dein english ist viel besser als mein Deutsch (hab lange kein deutsch gesprochen)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…