Android Question Need Help for my Project About Alarm Service

M.LAZ

Active Member
Licensed User
Longtime User
as usual i put my question and i wish from experts to solve my issue :
my project is a simple Alarm service with saved times for 1 year , there are 7 times every day per year , i retrieve alarm times from db and scheduling the alarm by a service . the alarm doesn't work i tested it on SDk 10,22,23.
i use
SetExactAndAllowWhileIdle (Time As Long, ServiceName AsString) ...
i attached my project... and you can make any changes...
thank you so much
 

Attachments

  • TestAlarmRh.zip
    338.7 KB · Views: 188
Last edited:

RauchG

Active Member
Licensed User
Longtime User
alarm.JPG

In the table tripoli "dte" field, the date format is incorrect.

Greetings
RauchG
 
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
Hi @Erel :)


What doesn't work?
the service doesn't fire in the alarm time ..

Have you tested it on an Android 4 device?

yes i tested it ..

Hi @RauchG :)
In the table tripoli "dte" field, the date format is incorrect.

may be in the sql editor the format is incorrect, but i use the exact format date in b4a which is Suitable for it.
as u see in the code i call this sub before executing the sql query

B4X:
SetDateTimeFormat(false)
then recall it after the execting
B4X:
SetDateTimeFormat(true)


B4X:
public Sub SetDateTimeFormat(toDefault As Boolean)
    If toDefault = False Then
        DateTime.DateFormat = "dd/MM"
        DateTime.TimeFormat = "HH:mm"
    Else
        DateTime.DateFormat = DateTime.DeviceDefaultDateFormat
        DateTime.TimeFormat = DateTime.DeviceDefaultTimeFormat
    End If
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are two things that can happen:

1. The next scheduled time is wrong.
2. The scheduled time is correct but the OS doesn't send the alarm at the exact time.

The second issue can happen on newer devices, so if it happens on Android 4 then it is most probably a different issue. Add some log messages and verify that you are setting the next alarm correctly.

Make sure to run your app in release mode and don't kill it with a swipe.
 
Upvote 0

RauchG

Active Member
Licensed User
Longtime User
So it would go.
I have my changes with '05 .07.2017 / Rh
characterized.

There is still one error: If the alarm is not running for an entire minute and you end the Activity "AlarmActivity" with the BackKey.

Look at it.

greeting
RauchG
 

Attachments

  • TestAlarmRh.zip
    338.6 KB · Views: 222
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
the alarm works fine , but i have some changes on it :
in the Main activity in event Activity_KeyPress (KeyCode As Int) As Boolean :
B4X:
        'StartService(AlarmService)                        ' Lazreg : 18/07/2017  i comment this line   and remark it to ** 
        CancelScheduledService(AlarmService)
        StopService(AlarmService)

        ' Lazreg : 18/07/2017   
        StartService(AlarmService) ' **

and in the Service_Start event

B4X:
     StopService("") '**
     StartServiceAt("", DateTime.Now + 30 * 1000, False)
     'StopService("")                    ' Lazreg : 18/07/2017  i comment this line  and remark it to ** in the first line


i tested the alarm on real devices :

Samsung Tab with Android ver 4.4.2
the alarm fires all the times with Remove from Recent Apps after every alarm.

Samsung J2 with Android ver 5.1.1
the alarm fires most of the times with Remove from Recent Apps after every alarm.

Samsung Note 4 with Android ver 6.0.1
the alarm fires sometimes with Remove from Recent Apps after every alarm.

how to schedule and process to fire alarm in the exact time especially devices with android ver > 6
and how to display the widget as designed ? i just see one label in the widget.
thank u so much for your help..
i updated the project file in the first post
 
Upvote 0

RauchG

Active Member
Licensed User
Longtime User
Change the entry in the manifest from

android:targetSdkVersion="25"
to
android:targetSdkVersion="19"

You must first uninstall your app. This could also be the reason why the app runs differently on different SDKs.

Greetings
RauchG
 
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
ok,, i will do that ,, but if i changed it to targetSdkVersion="19" is the app run normally with android 6 and later?
 
Upvote 0
Top