Android Question startservice to bring up dead activity

cengolo

Member
Licensed User
Longtime User
i have an application which also has an alarm component. i use startservice to call up the alarm, and i want the main activity to load and show some images in the app.

all is well if the application is sleeping or paused, but if the application is killed (the user might kill it), when the alarm fires, only a blank screen comes up in the phone.

i don't know how to run the killed app and bring to foreground. can someone point me in the right direction?

thanks in advance
 

cengolo

Member
Licensed User
Longtime User
after setting up the alarm, i am starting the service with:

StartServiceAtExact("starter",NextTimeInstance(aktifalarm.saat,aktifalarm.dakika), True)

from the service, i am starting the activity with:

StartActivity(Main)

i also have

#StartCommandReturnValue: android.app.Service.START_STICKY

in the service header, also have this sub enabled at the main:

Sub SetShowWhenLocked
Dim r As Reflector
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 6815872, "java.lang.int")
End Sub
 
Upvote 0

cengolo

Member
Licensed User
Longtime User
sorry, here is the corrected formatted reply:

after setting up the alarm, i am starting the service with:

B4X:
StartServiceAtExact("starter",NextTimeInstance(aktifalarm.saat,aktifalarm.dakika), True)

from the service, i am starting the activity with:

B4X:
StartActivity(Main)

i also have

B4X:
#StartCommandReturnValue: android.app.Service.START_STICKY

in the service header, also have this sub enabled at the main:

B4X:
Sub SetShowWhenLocked
Dim r As Reflector
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindow")
r.RunMethod2("addFlags", 6815872, "java.lang.int")
End Sub
 
Upvote 0

cengolo

Member
Licensed User
Longtime User
you mean i need to add another service module and fire the alarm from that service? and all the actions (ringing the alarm, bringing the main activity back to life, and stting up the next scheduled time for the alarm) will be handled by this new service module?
 
Upvote 0

cengolo

Member
Licensed User
Longtime User
Hi Erel,

I modified the code to your suggestion but something weird happens now. I set up the alarm, put the phone to sleep. The alarms fires up and opens the screen and the main activity comes up to the screen, no problem. probably because the app is still alive in the background.

But if I deliberately kill the app, in a few seconds it reappears on the screen, with all the settings lost (which is normal because I did not save the alarm settings yet). But why does it reappear? although I set up the service to fire up to five minutes later.

Would you mind checking up the code if I send you and tell me what am I doing wrong?


best Regards

Cenk
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
can I use
B4X:
android.app.Service.START_STICKY
with startforeground ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top