Android Question Cancel a date with KeyValueStore

Isac

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

derez

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

Isac

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

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

Peter Simpson

Expert
Licensed 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?
 

Isac

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

Isac

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

Isac

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

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

Isac

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