Android Question Widget error after update to Android 5

ducphu

Active Member
Licensed User
Longtime User
Hi All,

My app, with a calendar widget was developed and tested with my device, running Android 4.4. Recently update to Android 5. cause the widget fail to load its content. USB debug shows below code error when I try to add a widget to homescreen:
** Service (widget2x2s) Create **
** Service (widget2x2s) Start **
0
0
0
getTasks: caller 10252 does not hold GET_TASKS; limiting output

Here is the code of my widget:

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.
    Public rv As RemoteViews
End Sub
Sub Service_Create
    rv = ConfigureHomeWidget("widget2x2", "rv", 1440, "E-Calendar(Solar)")
End Sub

Sub Service_Start (StartingIntent As Intent)
   
    ' If a widget is removed from homescreen we don't need to do anything
    If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then Return
   
    ' We have to be sure that we do not start the service
    ' again if all widgets are removed from homescreen
    If StartingIntent.Action <> "android.appwidget.action.APPWIDGET_DISABLED" Then
        Dim schedule As Long
        Dim now As Long = DateTime.now
        schedule = DateUtils.SetDateAndTime(DateTime.GetYear(now), DateTime.GetMonth(now), DateTime.GetDayOfMonth(now),0,1,0)
        If schedule < now Then
           'skip to tomorrow
           Dim p As Period
           p.Days = 1
           schedule = DateUtils.AddPeriod(schedule, p)
        End If
        StartServiceAt("",schedule,True)
       
    End If
   
    ' Handle the widget events
    If rv.HandleWidgetEvents(StartingIntent) = False Then
        ' If the action is not handled by HandleWidgetEvents() then we
        ' probably were called by StartService() or StartServiceAt().
        ' So just update the widget.
       
        rv_RequestUpdate
    End If
   
    If IsPaused(screen_orientation) = True Then
        'Log("not running")
        StartService(screen_orientation)
    End If
End Sub

Sub rv_RequestUpdate

    rv.SetTextSize("Loading", 20)
   
    DateTime.DateFormat = "dd.MM.yyyy"
    Dim header As String = DateTime.date(DateTime.now)
    Dim day As Int= DateTime.GetDayOfWeek(DateTime.now)

    If day = 1 Then header = "Sun, " & header
    If day = 2 Then header = "Mon, " & header
    If day = 3 Then header = "Tue, " & header
    If day = 4 Then header = "Wed, " & header
    If day = 5 Then header = "Thu, " & header
    If day = 6 Then header = "Fri, " & header
    If day = 7 Then header = "Sat, " & header
   
    rv.SetImage("Bg",CommonCode.DrawFont("","Bg",0,0,False))
    rv.SetImage("Header",CommonCode.DrawFont(header,"Header",0,0,False))
    rv.SetImage("SL",LoadBitmapSample(File.DirAssets,"solar.png",20dip,20dip))
    rv.SetImage("Line",CommonCode.DrawFont("","Line",0,0,False))
   
    rv.UpdateWidget
   
    Dim first As String = "01." & DateTime.GetMonth(DateTime.Now) & "." & DateTime.GetYear(DateTime.Now)
    Dim first_day As Int = DateTime.GetDayOfWeek(DateTime.DateParse(first))
    first_day = first_day-2
    If first_day < 0 Then first_day = 6
    Dim no_of_days_in_mth As Int = DateUtils.NumberOfDaysInMonth(DateTime.GetMonth(DateTime.Now),DateTime.GetYear(DateTime.Now))
   
    Dim lb_no As Int
    Dim target_lb As String
    Dim date_str As String
    Dim pre_month As Int = DateTime.GetMonth(DateTime.Now) - 1
    Dim pre_year As Int = DateTime.GetYear(DateTime.Now)
    If pre_month = 0 Then
        pre_month = 12
        pre_year = pre_year - 1
    End If
    Dim prefix As Int = DateUtils.NumberOfDaysInMonth(pre_month,pre_year)
    prefix = prefix - first_day +1
    If first_day > 0 Then
        For i = 0 To first_day-1
            lb_no = i + 1
            target_lb = "ImageView" & lb_no
            rv.SetImage(target_lb,CommonCode.DrawFont(prefix,"Date_S",i,0,False))
            prefix = prefix+1
        Next
    End If
   
    rv.UpdateWidget
   
    Dim date As Int = 1
    Dim suffix As Int = 1
   
    For  j = 0 To 5
        For i = 0 To 6
            lb_no = i + j*7 + 1
            target_lb = "ImageView" & lb_no
            If j = 0 Then
                If i >= first_day Then
                    DateTime.DateFormat = "ddMMyyyy"
                    If DateTime.GetMonth(DateTime.Now) < 10 Then date_str = date & "0" & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
                    If DateTime.GetMonth(DateTime.Now) >= 10 Then date_str = date & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
                    If date <10 Then date_str = "0" & date_str
                    If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) <> 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,False))
                    If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) = 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,True))
                    date = date+1
                End If
            End If
            If j > 0 Then
                If date > no_of_days_in_mth Then
                    rv.SetImage(target_lb,CommonCode.DrawFont(suffix,"Date_S",i,j,False))
                    suffix = suffix+1
                End If
                If date <= no_of_days_in_mth Then
                    DateTime.DateFormat = "ddMMyyyy"
                    If DateTime.GetMonth(DateTime.Now) < 10 Then date_str = date & "0" & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
                    If DateTime.GetMonth(DateTime.Now) >= 10 Then date_str = date & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
                    If date <10 Then date_str = "0" & date_str
                    If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) <> 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,False))
                    If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) = 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,True))
                    date = date+1
                End If
            End If
        Next
        rv.UpdateWidget
    Next
   
    rv.SetVisible("Line",True)
    rv.SetVisible("LineS",True)
    rv.SetVisible("Loading",False)
    rv.UpdateWidget

    StopService("")
End Sub

Sub rv_Disabled
    StopService("")
    CancelScheduledService("")
End Sub

Sub Service_Destroy

End Sub

Sub Button1_Click
    StartActivity(Main)
End Sub

And here is list of lib I use:

BroadCastReceiver
Core
DateUtils
Gestures
IME
JavaObject
Phone
Reflection
SQL

May anyone help me please. Thank you.
 

ducphu

Active Member
Licensed User
Longtime User
The widget was running fine with android 4.4 and I didnt add this permission to the manifest. This issue happens only with android 5, and I'm not sure what is changed. And as Don suggested, I tried to add the permission but no luck.
Abt the log, if I check on filter, no error is seen. So I unfilter it. I just copy the one showed up when I click "add widget" If you need more, I will copy all the logs and post it later today.
 
Upvote 0

ducphu

Active Member
Licensed User
Longtime User
I design the widget with designer: add a textbox with black background showing "Now Loading"
Other information, e.g. day, month, year.. is updated by some rv_requestupdate command. The reason to call rv_requestupdate many times is to avoid the bandwidth limit in transferring data to the widget. So after all the data is completed updated, I will hide the "Loading" textbox to showthe calendar (you can see from the code).
What is happening now is after I add the widget, it stay with the "Now Loading" textbox, which, to me the update process can't be completed....
I attached photos showing the working widget and non-working widget.



Also, below is the more completed log:

 
Upvote 0

ducphu

Active Member
Licensed User
Longtime User
You mean the widget's size? In the designer, my base panel is set to 146x146

And here is the xml
B4X:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="110dp" android:minHeight="110dp" android:initialLayout="@layout/widget2x2s_layout" android:updatePeriodMillis="86400000" />

Which size should I use then?
 
Upvote 0

ducphu

Active Member
Licensed User
Longtime User
Sorry all, problem is fixed. It is somehow due to my testing device. An currupted root causes the issue. Thanks.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…