Android Question App allways present.

vbmundo

Well-Known Member
Licensed User
Hi,

I need to create an Alarm APP, then, when if APP is Open or closed must to work. And when the time is equal to Alarm configuration, need to open the Main Activity and show all as ussually show any Alarm APP.

But,

What to do ?

How can I create a NON STOP APP ?
How can this APP interrupt a Blocked Screen by Pin or Slider Password ?
How can the Service with Timer open the Activity when the APP is Hidden ?

I have great ideas for an Alarm Wake Up APP, but this topics are too important.

Regards
 

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi,

I need to create an Alarm APP, then, when if APP is Open or closed must to work. And when the time is equal to Alarm configuration, need to open the Main Activity and show all as ussually show any Alarm APP.

But,

What to do ?

How can I create a NON STOP APP ?
How can this APP interrupt a Blocked Screen by Pin or Slider Password ?
How can the Service with Timer open the Activity when the APP is Hidden ?

I have great ideas for an Alarm Wake Up APP, but this topics are too important.

Regards
Hi Pablo:

You can see the answers I have given you in your post the Spanish forum :D
https://www.b4x.com/android/forum/threads/consejos-para-despertador.71017/

You can also sweep for home, and read the tutorial service modules, the Spanish forum ;)
https://www.b4x.com/android/forum/threads/b4a-tutorial-módulos-de-servicio.42689/

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Wake Lock ? what's that ?

B4X:
' Check Lock Screen
Sub ComprobarBloqueoPantalla As Boolean

LogColor("ComprobarBloqueoPantalla",Colors.Blue)
Dim ok As Boolean

r.Target = r.GetContext

r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")

ok=  r.RunMethod("inKeyguardRestrictedInputMode")

LogColor("ComprobarBloqueoPantalla ok " & ok,Colors.Blue)

Return ok

End Sub


' unlock screen
Sub DesbloquearPantallaBloqueo
    LogColor("Desbloquear",Colors.Blue)
  r.Target = r.GetActivity
  r.Target = r.RunMethod("getWindow")
  r.RunMethod2("addFlags", 6815872, "java.lang.int")
  
End Sub

' lock screen
Sub BloquearPantallaBloqueo
  ' volver a bloquear pantalla (poner como estaba)
  
     LogColor("Bloquear",Colors.Blue)
  r.Target = r.GetActivity
  r.Target = r.RunMethod("getWindow")
  r.RunMethod2 ("clearFlags", 0, "java.lang.int")
  
End Sub

Happy weekend everyone

Saludos

Regards
 
Last edited:
Upvote 0

vbmundo

Well-Known Member
Licensed User
The service will start at the given time. You should then acquire a wake lock and start an activity.

Can you recursively restart the Service every 1 minute ?

What's the best practice if you wish to develop an Alarm APP ? the Service must be allways alert and on every minute give checks in the list of alarms and launch the Alarm Activity when the time recorded is the current

Runs the Service every minute or other choice ?

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
B4X:
' Check Lock Screen
Sub ComprobarBloqueoPantalla As Boolean

LogColor("ComprobarBloqueoPantalla",Colors.Blue)
Dim ok As Boolean

r.Target = r.GetContext

r.Target = r.RunMethod2("getSystemService", "keyguard", "java.lang.String")

ok=  r.RunMethod("inKeyguardRestrictedInputMode")

LogColor("ComprobarBloqueoPantalla ok " & ok,Colors.Blue)

Return ok

End Sub


' unlock screen
Sub DesbloquearPantallaBloqueo
    LogColor("Desbloquear",Colors.Blue)
  r.Target = r.GetActivity
  r.Target = r.RunMethod("getWindow")
  r.RunMethod2("addFlags", 6815872, "java.lang.int")
 
End Sub

' lock screen
Sub BloquearPantallaBloqueo
  ' volver a bloquear pantalla (poner como estaba)
 
     LogColor("Bloquear",Colors.Blue)
  r.Target = r.GetActivity
  r.Target = r.RunMethod("getWindow")
  r.RunMethod2 ("clearFlags", 0, "java.lang.int")
 
End Sub

Happy weekend everyone

Saludos

Regards

Hi Jesus,

What Object is "r" ?

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi Pablo:

Hi Jesus,

What Object is "r" ?


Pablo Sorry, the r belongs to the library reflection


B4X:
Dim r As Reflector

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
You don't need to start service every minute, in service (that is always open) check your condition and then start activity if it is needed

Hi,
I need to create an Alarm APP,

The service is not necessary to start every minute, but Pablo has said he wants to make an alarm. So you need to make a call each time if you want to activate your alarm time.
Something like this:
B4X:
StartServiceAt("", DateTime.Now + minutes * DateTime.TicksPerMinute, True) 'for minutes - para minutos

StartServiceAt("", DateTime.Now + seconds * DateTime. TicksPerSecond, True) ‘  for seconds - para segundos

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Hi Pablo:



I suggest you calculate how long it will be until the next alarm.
And you make a StartServiceAt at that time, or half. If you make calls very straight, you will exhaust the battery of the mobile device

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Jesus,

Thinks about this.

What if the user removes the battery from her phone, or restart her phone? the call persist even?

Remember how Alarm works.. you don't set to specific date... you can select MON - TUE - SAT as possible days.. and you can select more than one day.

When you STOP an Alarm today, maybe this Alarm need to be available tomorrow, and other days.

My fear is that if I now reset a StartService to within 4 days that call for some strange event is lost

I understand that if I put the service listening on every minute for possible Alarms can consume a lot of battery,

Is why we come to you to see if I can learn the best strategy and the best practice for my APP is not outdated and is rejected by users ... you have taught me to lock and unlock the phone, that's very good .. but I care about the service, and my fear is that finally, when it comes to sound the alarm comes, not work ... if that does not work, my APP will shit.

Thanks !!
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Jesus,

Thinks about this.

What if the user removes the battery from her phone, or restart her phone? the call persist even?

Remember how Alarm works.. you don't set to specific date... you can select MON - TUE - SAT as possible days.. and you can select more than one day.

When you STOP an Alarm today, maybe this Alarm need to be available tomorrow, and other days.

My fear is that if I now reset a StartService to within 4 days that call for some strange event is lost

I understand that if I put the service listening on every minute for possible Alarms can consume a lot of battery,

Is why we come to you to see if I can learn the best strategy and the best practice for my APP is not outdated and is rejected by users ... you have taught me to lock and unlock the phone, that's very good .. but I care about the service, and my fear is that finally, when it comes to sound the alarm comes, not work ... if that does not work, my APP will shit.

Thanks !!


What if the user removes the battery from her phone, or restart her phone? the call persist even?
No need to take out the battery of the phone, simply stop the device, and the service will stop (and all :D) That there are files where you can store the alarm information.

On the other hand, if you put #StartAtBoot: True, when the device restarts, the service will be launched.

When you STOP an Alarm today, maybe this Alarm need to be available tomorrow, and other days.
That serves the file where data stored alarms

My fear is that if I now reset a StartService to within 4 days that call for some strange event is lost

Put:
B4X:
#StartCommandReturnValue: android.app.Service.START_STICKY
or use Service.StartForeground
You can also look at my tutorial service modules :D:
https://www.b4x.com/android/forum/threads/b4a-tutorial-módulos-de-servicio.42689/
or tutorial Erel: https://www.b4x.com/android/forum/threads/service-modules.7542/

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
The App need to Close"

You can close the app but the service can continue to run.
And the service itself can kill if there are no outstanding alarms.

Regards
 
Upvote 0
Top