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
When compiling does not find the file:
values-v23.xml

If you do not pass I can not waste much time to look at the whole project.

I think assail you copy files from the folder Objects

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Sorry Pablo, that file is generated when compiling the path but had Sdk 22. And your App needs 23.

As Jack the Ripper was saying: Let us go by parts :D

The app does not stop, does not fail, see attached images. Look at the path, step by step run in debug mode to see why it does not work.

B4X:
If File.Exists(File.DirAssets,"alarms.alm")=True Then
You can not use the file alarm in File.DirAssets, is read-only. Copy the alarm file to the project folder, and read and store them there.

You have to finish the code so you can go to add alarm.

You have to change the code so that it does not constantly in the alarm window

The comparison is misconceived hours, watch a post Erel of like comparing hours

You have to make it to cancel the alarms, etc, etc

Advice: Make an analysis of how you want your app to work, of how you will manage alarms and then do the code. Personally I can not correct you all code.


Regards
 

Attachments

  • Screenshot_20160920-095236.png
    Screenshot_20160920-095236.png
    50.8 KB · Views: 208
  • Screenshot_20160920-095907.png
    Screenshot_20160920-095907.png
    47.9 KB · Views: 234
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
Following, as this has answers to some questions I have regarding an app I'm developing. My app actually works as intended, until the phone locks! Grrr
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Hi Friend.. thanks for your help.

You can not use the file alarm in File.DirAssets, is read-only. Copy the alarm file to the project folder, and read and store them there.

Ok, I change this for File.DirInternal

You have to finish the code so you can go to add alarm.

Yes, I must to finish this.


You have to change the code so that it does not constantly in the alarm window

This Activity only is opened when the user open the Alarm App, for the rest of times, only the Service must works.

The comparison is misconceived hours, watch a post Erel of like comparing hours

I will look this POST

You have to make it to cancel the alarms, etc, etc

: Make an analysis of how you want your app to work, of how you will manage alarms and then do the code. Personally I can not correct you all code.

Yes, My code have only 1 day work. this analysis that you speak depends of the code possibilities.. I can imagine an specific behaviour but if Android, or Basic4Android works in different way, I can not do it.

My Desired Behaviour is

  • The user can Open the Alarm Manager at any time.
  • A service should be alert to the hours of each alarm, why, I'm not clear how to do, because it would have to execute a routine every minute. I'm not comfortable with the StartServiceAt because if the user or reset the Android phone, the call stack is lost. is a critical application, if an alarm fails, the user will not wake up and hate me
  • This Service Routine, must dissallow the Blocked screen (you helped me with that) and Launch another Activity Screen with Alarm running
The most critical desicion is "HOW CAN I MANAGE THE SERVICE TO RUNS EVERY MINUTE (with a Timer) AND RUNS IN EVERY MOMENT", As you can see, my Service is a Sticky Service, and have the StartAtBoot=True

This is not a CODE Question.. this is a STRATEGIC Question..

The answers to this questions, may help to a lot of users.

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User

My first APP that you can see here:
https://play.google.com/store/apps/details?id=com.bgsoft.easyschedule
and that is now obsolete, it functions as an alarm, and I have no need to call a timer or a service every minute.Like I said, I calculate the alarm time next, divide the time in half, and call StartServiceAt, Android sometimes I kill the service but reruns, and it is as simple as reading the file alarms and recalculating the next call to StartServiceAt
Read my tutorial service modules, there extensively explain the problems I had with Android kill the service, but with what I said my program works and this four years ago.

This is not a CODE Question.. this is a STRATEGIC Question..

The answers to this questions, may help to a lot of users.
You know the Spanish Forum am among those who most help, but one thing is to help and make other analysis work someone, that has to do the programmer / analyst (ie, you :D)
However I will give sequence to follow, or rather, I would, but without going into much detail.

The sequence is easy:
1) I enter the APP and add one or n alarms
2) Save to file alarms
3) When I go check if there are alarms
4) If no alarms, I do nothing
5) If there are alarms, launch the "Alarms" service

6) Enters Service Alarm
7) Read the file alarms
8) If there are no alarms (if reboot) kills service
9) If there is alarm, which is calculated by the nearest
10) If the alarm time, call activity that alarm
11) If you are not in alarm time, divided by two then and call StartServiceAt

By dividing by two you make sure that if you kill Service, to re-enter you can make the alarm. When you leave a few minutes you do not need to divide. If there is an alarm, the StartServiceAt will re-enter the service, and you will go to point 6)


Regards
 
Last edited:
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Following, as this has answers to some questions I have regarding an app I'm developing. My app actually works as intended, until the phone locks! Grrr

That question is also impossible to know what happens.
If you work with pictures, maybe you load many and be a memory problem.
Could be a problem of saturation stack of recursive calls.

No more data is difficult to know

regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Jesus,

At first, Thanks for your time and help..

At second... your analysis is correct, but I have an important question.

Can the same service make the call to itself ? (this not create a long an dangerous recursively stack) ?
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Jesus,

At first, Thanks for your time and help..

At second... your analysis is correct, but I have an important question.

Can the same service make the call to itself ? (this not create a long an dangerous recursively stack) ?

In service, in Sub Service_Start (StartingIntent As Intent) you generate the call, and if you do not generate more, just have that.
Theoretically you just have to generate a call, which is the nearest in time. If you want to ensure that you do not generate more call, kills the Schedule as follows:

B4X:
CancelScheduledService (Me)
And if from outside, you pass the service name

Regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Perfect,

Then.. the steps are

1. On every File modification (when the user ADD an Alarm, or when the user MODIFY an Alarm, or when an Alarm expires) I need to run
CancelScheduledService (Alarmas)

2. Browse the file looking for the nearest active alarm in time
3. Do an StartServiceAt( this Time - some minutes )
4. In SERVICE_CREATE, I must to repeat the File Browse (if Android cancel my Service my StartServiceAt will lost)

But... if I go to Service some minutes before, I need to iterate until the desired HOUR AND MINUTE comes.

This is the point of my question

Why not do an StartServiceAt to the real and exact delay ?

If ANDROID quit this service, and recreate, all code included into SERVICE_CREATE must to launch the desired ALARM.

IF you start a service and immediately execute an alarm that you give what chance have Android to cancel the service?

I think if do you come a few minutes earlier, and then iterating or leave a loop or timer waiting for the right time, you have more chances that you cancel Android.

But I'm no expert on this, so I ask.

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Perfect,

Then.. the steps are

1. On every File modification (when the user ADD an Alarm, or when the user MODIFY an Alarm, or when an Alarm expires) I need to run


2. Browse the file looking for the nearest active alarm in time
3. Do an StartServiceAt( this Time - some minutes )
4. In SERVICE_CREATE, I must to repeat the File Browse (if Android cancel my Service my StartServiceAt will lost)

But... if I go to Service some minutes before, I need to iterate until the desired HOUR AND MINUTE comes.

This is the point of my question

Why not do an StartServiceAt to the real and exact delay ?

If ANDROID quit this service, and recreate, all code included into SERVICE_CREATE must to launch the desired ALARM.

IF you start a service and immediately execute an alarm that you give what chance have Android to cancel the service?

I think if do you come a few minutes earlier, and then iterating or leave a loop or timer waiting for the right time, you have more chances that you cancel Android.

But I'm no expert on this, so I ask.

Regards

Hi, Pablo

I have created several alarm type programs, and specifically one that is an alarm clock :D.
My experience with long and Android services, is that sometimes killed them and did not return, or did not give them time to return to activate the alarm.
When I made that system to divide by two the problem is over. Until that moment came much I did not work.
That divide by two only do it if there are more than 60 minutes for the next alarm, and so enters and should not do any waiting loop.

If you think android will kill the service and will not run again, and if you do not mind a notification in the status bar, you can use Service.StartForeground, even if the icon leads to use this bothers you, you can use an invisible image.

If you use:
B4X:
#Region Service Attributes
#StartCommandReturnValue: android.app.Service.START_STICKY
This code is so that if Android or the user to delete the background processes or memory if the service stops, get going again.
What to read the file in the create is that sometimes kills Android service and does not enter Sub Service_Destroy
After much discussion in this forum, the final answer was:
The correct statement is that there is no guarantee that Service_Destroy will be raised when the process is killed. The same is correct for Activity_Pause.

I explain this in my tutorial: https://www.b4x.com/android/forum/threads/b4a-tutorial-módulos-de-servicio.42689/

regards
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Wow

You're a Machine !! I read all your POSTS with devotion.

clarifying this

1. when the user set an alarm for withing 5 hours, in the Alarm Manager Activity, I need to launch the StartServiceAt(Service, <for 2.3 hs>)
2. In 2.30 hs the Service run the START SUB.... and then, into the START SUB, you recalculate this time, and launch another Service call for 1.15 hs... and then, again and again.. and when only rest 1 o 2 minutes.. you run an LOOP waiting the exactly time ?

I have

B4X:
#Region  Service Attributes
    #StartAtBoot: True
    #StartCommandReturnValue: android.app.Service.START_STICKY
#End Region

Reading your words, I understand that I must not use SERVICE_CREATE to critical operations.. SERVICE_START is better.

But, How manage more than ONE Alarm ? the user can SET an Alarm withing 1 hour , and another withing 30 minutes.

Thanks !!
 
Upvote 0

vbmundo

Well-Known Member
Licensed User
Look Jesus

https://www.b4x.com/android/forum/threads/now-android-6-servicestartatexact-not-accurate.65117/

Some users use the AlarmManager service of Android, but.. What you recommend ?

I wish a service that manage all alerts and opens the Activity Alarm

But some users, interact with this Android service, obviously with error by the new Android versions and changes in SO make an APP obsolete in one day.

I'm thinking that when my APP will finish, I will submit the Source code to free use.

Regards
 
Upvote 0

bgsoft

Well-Known Member
Licensed User
Longtime User
Wow
You're a Machine !! I read all your POSTS with devotion.
do not confuse my name with that of another, my father was not a carpenter :D (It's a bad joke)

1. when the user set an alarm for withing 5 hours, in the Alarm Manager Activity, I need to launch the StartServiceAt(Service, <for 2.3 hs>)
B4X:
StartServiceAt("", MinutesService*DateTime.TicksPerMinute, True)

2. In 2.30 hs the Service run the START SUB.... and then, into the START SUB, you recalculate this time, and launch another Service call for 1.15 hs... and then, again and again.. and when only rest 1 o 2 minutes.. you run an LOOP waiting the exactly time ?
Many devotion has not put my writing when again asked the same :D , I said:
When I made that system to divide by two the problem is over. Until that moment came much I did not work.
That divide by two only do it if there are more than 60 minutes for the next alarm, and so enters and should not do any waiting loop.

B4X:
  ' MinutesService I put on the nearest alarm 
  If MinutesService>60 then MinutesService= MinutesService/2
  StartServiceAt("", MinutesService*DateTime.TicksPerMinute, True)

Reading your words, I understand that I must not use SERVICE_CREATE to critical operations.. SERVICE_START is better.
Mr. Pablo please, read any tutorial on service modules. I at no time have said that.
The SERVICE_CREATE comes when the service is created as its name indicates :D, and SERVICE_START after create the first time.
SERVICE_START then enter on each call if not destroyed the service.
I would SERVICE_START, reading the file alarms and calculate the next alarm.

But, How manage more than ONE Alarm ? the user can SET an Alarm withing 1 hour , and another withing 30 minutes.

Only there will be a next alarm to the current time and day, if there are is an error two does not make sense to activate the same alarm twice :confused:.

the user can SET an Alarm withing 1 hour , and another withing 30 minutes
1 hour = 60 minutes
Alarm which is the nearest to the current time, 1 hour or 30 minutes? :rolleyes:

Regards
 
Upvote 0
Top