Android Question Timer_Alarm subroutines

B4A_!ADT

Member
Licensed User
Longtime User
I'm new to B4A and I don't have any code to post but the idea I'm playing with is to be able to enter a start time, like 7 ( as in 7 am ) and at the entered time, a notification will pop. Then, for the rest of day after that first time, a notification would pop every x hours throughout the day, where x is the amount of time that is to pass between future notifications. So , if x = 3, then first notification happened at 7am and next one is at 10am, 1pm, 4pm, etc.

Also, after one enters the numbers above, they should be able to close the data entry app, and the notification ( or the starting of another app, if that's possible ) should then happen at the correct time.

If I can get the objects/libraries, I can write the code.

Thanks for any help.
 
Last edited:

B4A_!ADT

Member
Licensed User
Longtime User
Thank you Erel, I knew about that service but wasn't sure if there were any other options. I've got something basic working using ServiceStartAt, but now my other question is...after doing the data entry part and so now the service is scheduled, the app should be closed and when the service fires the same app opens and notifies the user with a list of things to do. Is that doable ( it must be ) and if so, what is the basic method ( It may be in the tutorial section, but I don't know what such a thing would be called ) ?
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
create an activity with the list of things to do,,then start activity by 'startactivity(name)' from your service..
 
Upvote 0

B4A_!ADT

Member
Licensed User
Longtime User
I now have all the main components working ! I do a notification from the "start_service" module and once the notification is pressed, then the reminder activity fires. I have some questions, though.

1) If I had used startactivity(), it would start immediately and then pause WHATEVER app. the user happened to be using at that time, is that right ?

2) SQLite doesn't support CREATE DATABASE, does it ? If not, then we have to just make and reference whatever tables are needed, without a DB "container" ?

3) I put my own notification icon in the correct folder, but it gets removed for some reason ! What's going on with that and how to use my own icons ?

4) Beeper Objects don't block when they run, so how can I know when to use beep_object.Release ? If I put such a line right after the initialize() line...it gets released right away.

5) Cursor objects can't be initialized ( no member for that action ), but while working out my code I sometimes got exception errors that a Cursor wasn't initialized. Am I missing something ?

6) The service must not be stopped by the OS ( for reclaiming resources, etc ). Can it be so configured ?


I use B4A ver. 3 and SQLite ver. 1.20

Thank you for pointing me in the right direction.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1) It will pause the current visible activity. Other processes can continue running in the background.
2) Each file is considered a complete database.
3) You should set the file to be read-only (or use #AdditionalRes).
4) You don't need to release the object unless you are creating a new object each time.
5) You will need to check your code. SQL.ExecQuery always returns an initialized cursor.
6) Creating a sticky service - long running background tasks
 
Upvote 0

B4A_!ADT

Member
Licensed User
Longtime User
For 3) Setting to read-only works...but while the full image is seen in the status bar BEFORE clicking it once it's hit only a part of the image shows ( It's 480x640 PNG ). Can this be fixed ? Probably the res is too high to show in that view...My B4A version doesn't support #AdditionalRes, according to the error.

For 5) I had got it to work before, but IIRC the error came up as I was using the wrong SQL object name for the object I was working with.

Thanks Erel !
 
Upvote 0

B4A_!ADT

Member
Licensed User
Longtime User
When the reminder activity's done, and the back button's pressed the notification object gets destroyed. But if the recent apps button is pressed, the reminder act. is opened, not the main act. which is what I thought would happen. I then put Activity.Finish in Activity_Pause of reminder act, but it didn't work.

Is there a solution for this ?
 
Last edited:
Upvote 0

B4A_!ADT

Member
Licensed User
Longtime User
This is the activity which is described in my last post. I don't see any way to add code tags on this forum...

So, if I'm in the reminder_act, but main_act has already been closed using the back button before notification fires, then reminder_act opens when recent apps button is pressed ( After back button is used to close the reminder_act ). Neither back button or activity.finish removes an activity from the Android stack...? People that use my app will want main_activity to open, not the other activity when recent apps button is used.



B4X:
Sub Process_Globals

	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

  Dim  temp_str As String : temp_str = " "

End Sub

Sub Globals

	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	
  Dim str As String
  Dim Remind_me As Label
  Dim Listview1 As ListView
  Dim cursor1 As Cursor

End Sub

Sub Activity_Create(FirstTime As Boolean)

  Dim row_cnt, row As Int

	
	Activity.LoadLayout("My_reminder")	
	Activity.Color = Colors.Blue
	
	For row = 0 To Main.tempList.Size - 1  ' tempList is a sorted List, made in main_activity
	
		        Listview1.AddSingleLine( Main.tempList.Get(row) )

	Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)


	Cnt_Time.noti.Cancel(1)
	Activity.Finish  
	
End Sub[code/]
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [ code ] [ /code ] tags (without spaces) when posting code.

The recent apps button brings back the last activity. You can use StartActivity to show a different activity. Use a process global variable to set the state of the reminder activity and then start it. In Activity_Resume check the value of this variable. Now you should decide whether to keep the current activity or show a different one.
 
Upvote 0

B4A_!ADT

Member
Licensed User
Longtime User
Thank you, Erel I'll check out your option ! Did you mean Activity_pause in reminder_activity instead of Act_resume ( Resume won't happen for that activity when back button's pressed ) ?

I didn't know I had to add the tags manually ( thought I could highlight code and hit a button )...got it now !
 
Last edited:
Upvote 0
Top