Hi all,
I made a widget that shows the name of the saints for each day and I have two questions:
1. After installation, it takes around 20 seconds for widget to be populated. It takes data from database file. Question is why it takes so much time to fetch data from DB and is it maybe normal?
2. I need to update my widget once a day, at midnight, or minute after. For my widget I took a widget example from forum and adjusted it to my needs (at least I think so ).
 ). 
For testing purposes I put a counter (x) to increase by 1 when widget is updated. for update I try to use TimeToNextMinute. What happens is that when I install the widget, counter increases by two immediately (it should not increase until first "controlled" update) and exactly 1 minute after specified time counter starts to tick veeery fast.
So my big question is: What am I doing wrong?
Below is the widget code
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			I made a widget that shows the name of the saints for each day and I have two questions:
1. After installation, it takes around 20 seconds for widget to be populated. It takes data from database file. Question is why it takes so much time to fetch data from DB and is it maybe normal?
2. I need to update my widget once a day, at midnight, or minute after. For my widget I took a widget example from forum and adjusted it to my needs (at least I think so
For testing purposes I put a counter (x) to increase by 1 when widget is updated. for update I try to use TimeToNextMinute. What happens is that when I install the widget, counter increases by two immediately (it should not increase until first "controlled" update) and exactly 1 minute after specified time counter starts to tick veeery fast.
So my big question is: What am I doing wrong?
Below is the widget code
			
				B4X:
			
		
		
		Sub Service_Create
    x=0
    rv = ConfigureHomeWidget("wdgKatKal", "rv", 0, "Katolicki kalendar")
    rv_RequestUpdate
End Sub
Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then Return
    If rv.HandleWidgetEvents(StartingIntent) = False Then
        rv_RequestUpdate
    End If
    If StartingIntent.Action <> "android.appwidget.action.APPWIDGET_DISABLED" Then
        StartServiceAt("", TimeToNextMinute, False)
    End If
End Sub
Sub rv_RequestUpdate
   x=x+1
    mnt = DateTime.GetMonth(DateTime.Now) 'find the current month
    yr = DateTime.GetYear(DateTime.Now) 'find the current year
   
    Database
    DateTime.DateFormat = "d.M.yyyy" ' bila je tu točka na kraju
    DateTime.TimeFormat = "HH:mm"
    'saint of the day'
    dbC = dbS.ExecQuery2 ("SELECT sveci,d,m,blagdan,pomicni_blag_"&yr&" FROM 'KatKalendar' WHERE m = ? AND d = ?", Array As String(mnt,DateTime.GetDayOfMonth(DateTime.Now)))
    dbC.Position=0       
...   
   
    dt = dbC.GetString("d")+x
    datum = dt&"."&mnt&"."&yr&"." 
    dan = Days_hr(DateTime.GetDayOfWeek(DateTime.Now))
   
    rv.SetText("lblSveci",sveci)
    rv.SetText("lblDat",datum)
    rv.SetText("lblDan",dan)
    rv.SetText("lblFeast",feast)
    rv.UpdateWidget
End Sub
Sub rv_Disabled
    StopService("")
End Sub
Sub Service_Destroy
End Sub
Sub Database
    Dim ruta As String
   
    If File.ExternalWritable Then
            ruta = File.DirDefaultExternal
        Else
            ruta = File.DirInternal
    End If
'# Always copy new DB file
    File.Copy(File.DirAssets, "kalendar.db", ruta, "kalendar.db")
    dbS.Initialize(ruta, "kalendar.db", True)
End Sub
Sub TimeToNextMinute As Long
    Dim ret As Long
ret=DateTime.TimeParse("10:28")
ret = ret + DateTime.TicksPerMinute
    ret = ret - (ret Mod DateTime.TicksPerMinute)   
    Return ret
End Sub 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		