Android Question Schedule app

Rusty

Well-Known Member
Licensed User
Longtime User
I would like to:
  1. Run an application
  2. when the application is "finished"
  3. re-schedule the app to run in X minutes
  4. ...app runs again
  5. re-schedule occurs again
  6. ...ad infinitum
  7. The operation needs to persist through power off and power on of the device
I am thinking this would be to service with startatboot. I don't know how to "hide" the Main application or ? to allow the user to use the device for other things while the service counts down before it restarts/reshows the main app.

Any advice on this is appreciated.
Rusty
 

DonManfred

Expert
Licensed User
Longtime User
On first start create a service and inside the service set the time when it have to run again...

See Service-tutorials.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Manfred,
Thank for the advice. I am not sure I understand it though.
I envision, starting my app, having the app start a service, have a StartServiceAt reschedule the service.
I'd like the main application to "Hide" while the service is sleeping and a Sub within the main app to fire and show a "reminder" when the service fires. Then the user would reuse the main application, it would then "finish" and tell the service when to fire again, the whole process would repeat.
I can create the service and schedule it fine, but I don't know how to "hide" the main application while the service sleeps.
Thanks,
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Hi Erel,
I have written a very small sample application:
B4X:
MAIN:
Sub Activity_Create(FirstTime As Boolean)
    StartServiceAt(Reminder, DateTime.Now + 60000, True)
    Activity.Finish
End Sub

Sub RemindMe
    Msgbox("you need to ", "Notice")
End Sub
...

REMINDER: (service)
Sub Service_Start (StartingIntent As Intent)
   CallSub(Main, "RemindMe")    'remind them now
End Sub

I get: android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@410bf618 is not valid; is your activity running?
I tried CallSubDelayed and it never fired Main.
When I remove Activity.finish, it fires just fine and doesn't blow up, but my users are stuck with my application while it should be sleeping.
Any advice?
thanks
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Sorry, Erel, I had tried Callsubdelayed; changed it to callsub and failed to copy the correct code.
However, the good news is that I used your Widget example and it works supurbly.
Thanks,
Rusty
 
Upvote 0
Top