Android Question I want to make a simple alarm clock using service?

xiaoyao

Active Member
Licensed User
Longtime User
I want to make a simple alarm clock using service (timer_fw)
how to change Activity( main).lable1.text?
 

hatzisn

Expert
Licensed User
Longtime User
If you want to use a service or a receiver the shorter period for calling it with StartServiceAtExact or StartReceiverAtExact is 30 minutes. You also have to add in manifest the proper permissions (check the forum as I do not remember them at all).
 
Upvote 0

xiaoyao

Active Member
Licensed User
Longtime User
Call a public Sub of the Main that updates the Label (e.g. CallSubDelayed2(Main, "UpdateUI", "some text").

It is recommended to create a B4XPages project.

You should create a foreground service.
My timer often stops running, download it to help me fix it, thank you

CallSub(Main,"Service_ShowTimer")
change to CallSubDelayed, now it's ok,thank you
if my sub no agrmemuent,how to CallSubDelayed(main,"Service_ShowTimer",null?) or arry(null)?

B4X:
Private Sub btService_Timer_Click
    StartService(Timer_FW)
End Sub


Timer_FW.bas

Sub Service_Start (StartingIntent As Intent)
    'Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
    Service.AutomaticForegroundMode=1
    timer1.Initialize("Timer1", 1000)
    timer1.Enabled = True
End Sub

Sub Timer1_tick
    pubbas.TickCount=pubbas.TickCount+1
    Count2=Count2+1
    If pubbas.Activity_Show=True Then
        CallSub(Main,"Service_ShowTimer")
    End If
End Sub
 

Attachments

  • zipServiceTimer.zip
    5.2 KB · Views: 46
Last edited:
Upvote 0

xiaoyao

Active Member
Licensed User
Longtime User
1.服务人员可能被杀害
在开始时,如果将接口切换出去,将变量更改为"进入前景",其他应用程序将进入前景,并且变量值将改变为非前景值。
后台服务按此变量调用一个过程的主要接口,修改UI闹钟已经过秒和倒计时文本。

但它在大约7秒后就停止了。
注1:前台服务自动模式,服务.自动前置模式=1
注2:电话节电策略应设定为(无限),以确保服务不会长期中断运作
 
Upvote 0

xiaoyao

Active Member
Licensed User
Longtime User
If you want to use a service or a receiver the shorter period for calling it with StartServiceAtExact or StartReceiverAtExact is 30 minutes. You also have to add in manifest the proper permissions (check the forum as I do not remember them at all).
This is also a very good method, but I don’t know how to do it now. I’ll learn it slowly. Thank you.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…