Android Question Cancel a date with KeyValueStore

Discussion in 'Android Questions' started by Isac, Apr 7, 2015.

  1. Isac

    Isac Active Member Licensed User

    Hello

    How do I delete a stored date with KeyValueStore?


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



    module boot

    Code:
    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

    ----------------
    ----------------
    --------------
    ---------------
     
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    Hello @Isac,
    I've not tried this code but in theory it should work for you, I think...
    Code:
    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
     
    DonManfred likes this.
  3. derez

    derez Expert Licensed User

    Remember that files in File.DirDefaultExternal are deleted at application installation.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
    Peter Simpson and DonManfred like this.
  5. Isac

    Isac Active Member Licensed User

    The module boot always detects the presence of the date, alerting with the module starts.


    Main module
    Code:
    ---------------
    -------------
    -------------

    memoria.Initialize(
    File.DirDefaultExternal,"datastore"

    memoria.PutSimple(
    "date",date)     

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

    Boot module

    Code:
    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

    --------------------
    --------------------
    ---------------------
    -------------------
     
  6. Peter Simpson

    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?
     
  7. Isac

    Isac Active Member Licensed User

    yes one main module and two service

    The condition of the insert in the module Main?

    thank you
     
  8. Isac

    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.

    Code:
    #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
     
  9. Isac

    Isac Active Member Licensed User

    the service module you can start only once?

    Code:
    #Region  Service Attributes
        
    #StartAtBoot: true
    #End Region
     
  10. Peter Simpson

    Peter Simpson Expert Licensed User

    Add the following to your long running service.
    Code:
    #Region Service Attributes
    #StartAtBoot: true
    #StartCommandReturnValue: android.app.Service.START_STICKY
    #End Region
    You could always set StartServiceAt(...) to every 60 seconds...
     
    Last edited: Apr 14, 2015
  11. Isac

    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
    Code:
    #StartCommandReturnValue: android.app.Service.START_STICKY
    Code:
    #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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice