Android Question Need Help for my Project About Alarm Service

Discussion in 'Android Questions' started by lazreg, Jul 2, 2017.

  1. lazreg

    lazreg Member Licensed 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
     

    Attached Files:

    Last edited: Jul 17, 2017
  2. Erel

    Erel Administrator Staff Member Licensed User

    What doesn't work?

    Have you tested it on an Android 4 device?
     
    lazreg likes this.
  3. RauchG

    RauchG Active Member Licensed User

    alarm.JPG

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

    Greetings
    RauchG
     
    lazreg likes this.
  4. lazreg

    lazreg Member Licensed User

    Hi @Erel :)


    the service doesn't fire in the alarm time ..

    yes i tested it ..

    Hi @RauchG :)
    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

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

    Code:
    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
     
  5. Erel

    Erel Administrator Staff Member Licensed 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.
     
  6. RauchG

    RauchG Active Member Licensed 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
     

    Attached Files:

    lazreg likes this.
  7. lazreg

    lazreg Member Licensed User

    still testing and some changes have made
     
  8. lazreg

    lazreg Member Licensed 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 :
    Code:
    '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

    Code:
    StopService(""'**
         StartServiceAt(""DateTime.Now + 30 * 1000False)
         
    '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
     
  9. RauchG

    RauchG Active Member Licensed 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
     
  10. lazreg

    lazreg Member Licensed User

    ok,, i will do that ,, but if i changed it to targetSdkVersion="19" is the app run normally with android 6 and later?
     
  11. RauchG

    RauchG Active Member Licensed User

    Yes. Runs with me under Android all to Android 8 (Beta)

    Greetings
    RauchG
     
  12. lazreg

    lazreg Member Licensed User

    ;) thank u so much
     
    RauchG likes this.
  13. lazreg

    lazreg Member Licensed User

    hi again,,
    when rebooting the device the app crashes
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Enable USB debug mode and connect to the device. This will allow you to see the error message.
     
    lazreg likes this.
Loading...