Android Question Cancel a date with KeyValueStore

Isac

Active Member
Licensed User
Longtime User
Hello

How do I delete a stored date with KeyValueStore?


module Main
----------------
---------------
--------------



module boot

B4X:
Sub Process_Globals
  
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim memoria As Keyvaluestore
    Dim dDouble As Double
   
End Sub
Sub Service_Create
memoria.Initialize(File.DirDefaultExternal,"datastore")   
End Sub

Sub Service_Start (StartingIntent As Intent)

Dim dTemp As String = memoria.GetSimple("date")
Dim dDouble As Double =dTemp
StartServiceAt(starts,dDouble,False)

'I tried it, but when I turn on and turn off the phone I throw an error
memoria.Remove("date")        


StopService("")
End Sub

Sub Service_Destroy

End Sub



module starts

----------------
----------------
--------------
---------------
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @Isac,
I've not tried this code but in theory it should work for you, I think...
B4X:
Sub Service_Start (StartingIntent As Intent)
    Dim Memoria As KeyValueStore
    'Create file
    Memoria.Initialize(File.DirDefaultExternal, "datastore")
    'Put date into file
    Memoria.PutSimple("date", DateTime.Date(DateTime.Now))  
      
    'Retrieve and print date in logs
    Log(Memoria.GetSimple("date"))
  
    'Remove date
    Memoria.Remove("date")  
  
    'Check to see if the date has been removed
    Log(Memoria.GetSimple("date"))  
End Sub
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Remember that files in File.DirDefaultExternal are deleted at application installation.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Remember that files in File.DirDefaultExternal are deleted at application installation.
Files will only be deleted from this folder if you uninstall the app.

There was a bug on some Android 2.2 devices where this folder was deleted by mistake during installation.
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
The module boot always detects the presence of the date, alerting with the module starts.


Main module
B4X:
---------------
-------------
-------------

memoria.Initialize(File.DirDefaultExternal,"datastore") 

memoria.PutSimple("date",date)     

StartServiceAt(boot,date,False)
------------------------------------------------------------

Boot module

B4X:
Sub Process_Globals

    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim memoria As Keyvaluestore
    Dim dDouble As Double

End Sub
Sub Service_Create
memoria.Initialize(File.DirDefaultExternal,"datastore")
End Sub

Sub Service_Start (StartingIntent As Intent)

Dim dTemp As String = memoria.GetSimple("date")
Dim dDouble As Double =dTemp
StartServiceAt(starts,dDouble,False)


'I tried so but when I turn off and turn on the module boot tells me that there is still the date
Main.memoria.Remove("date")       '<--------------------


StopService("")
End Sub

Sub Service_Destroy

End Sub

------------------------------------------------------

starts module

--------------------
--------------------
---------------------
-------------------
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
If your main module is always inserting the date, then your boot service module will always read that date. You need to create a condition where the main module only inserts the date once and not every time it starts.

Am I correct in saying that you are describing 1 main module and 2 services?
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
Am I correct in saying that you are describing 1 main module and 2 services?

yes one main module and two service

The condition of the insert in the module Main?

thank you
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
With this condition, the phone tells me always and only for a day if I turn off and turn on the phone.
I wish I notice only once in a day.

B4X:
#Region  Service Attributes
#StartAtBoot: true
#End Region

Sub Process_Globals
  
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim memoria As Keyvaluestore
    Dim dDouble As Double
   
End Sub
Sub Service_Create
memoria.Initialize(File.DirDefaultExternal,"datastore")   
End Sub

Sub Service_Start (StartingIntent As Intent)

Dim dTemp As String = memoria.GetSimple("date")
Dim dDouble As Double =dTemp

If Main.date=Main.DATA Then      '<------------------------- I compare dates
StartServiceAt(starts,dDouble,False)
End If

StopService("")

End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
the service module you can start only once?

B4X:
 #Region  Service Attributes
    #StartAtBoot: true
#End Region
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Add the following to your long running service.
B4X:
#Region Service Attributes
#StartAtBoot: true
#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
You could always set StartServiceAt(...) to every 60 seconds...
 
Last edited:
Upvote 0

Isac

Active Member
Licensed User
Longtime User
I'm sorry but what is this command?
I entered but nothing changes, if I turn off and turn on the phone the date is always notified
B4X:
#StartCommandReturnValue: android.app.Service.START_STICKY

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

Sub Process_Globals
 
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim memoria As Keyvaluestore
    Dim dDouble As Double
  
End Sub
Sub Service_Create
memoria.Initialize(File.DirDefaultExternal,"datastore")  
End Sub

Sub Service_Start (StartingIntent As Intent)

Dim dTemp As String = memoria.GetSimple("date")
Dim dDouble As Double =dTemp

If Main.date=Main.DATA Then      '<------------------------- I compare dates
StartServiceAt(starts,dDouble,False)
End If

StopService("")

End Sub

Sub Service_Destroy

End Sub
thanks
 
Upvote 0
Top