Android Tutorial Android home screen widgets tutorial - part I

Status
Not open for further replies.

Wembly

Member
Licensed User
Longtime User
You are correct. Make sure to run your app in Release mode. If it still crashes then you need to check the logs (connect with USB debug mode).

Erel - The app is running in release mode in addition I've now managed to capture the error generated when the app crashes:


The code for the service is:

B4X:
Sub Process_Globals

    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim widget As RemoteViews
  
End Sub

Sub Service_Create
  
    widget = ConfigureHomeWidget("Widget7Day","widget",60,"Shift Calendar 7 Days")
    widget.UpdateWidget
  
 
End Sub

Sub Service_Start (StartingIntent As Intent)

    If widget.HandleWidgetEvents(StartingIntent) Then Return

End Sub

Sub Service_Destroy

End Sub

Sub widget_RequestUpdate
    ...

As mentioned previous the widget works fine as long as the app is running memory, but when they click the widget when the app is not running in memory then it crashes.

Any ideas I've searched but not found anything useful information.

Thanks!
 
Last edited:

Wembly

Member
Licensed User
Longtime User
Thanks Erel but just found the issue - I had an incorrect initialize in Process Globals which I've now moved and all is good.
 

CyclopDroid

Well-Known Member
Licensed User
Longtime User
It's possible start the Widget after the install Application? Or start it, when the Widget it's moving of Widget Menu to screen phone?
Thanks.
 

CyclopDroid

Well-Known Member
Licensed User
Longtime User
My widget can't automatic start after reboot, how to fix this?
Have you insert the True boolean to StatAtBoot into Service Attribute of you widget code?

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

Happy New Year to all
 

Cebuvi

Active Member
Licensed User
Longtime User
Hello Erel,

I have written a small widget and I can not fire the click events. Some day ago I write another widget and it worked perfectly and still does, but not this example.

I send you the code.

Thanks

Cesar
 

Attachments

  • W2.zip
    9 KB · Views: 424

Cebuvi

Active Member
Licensed User
Longtime User
Hello Erel,

I have written a small widget and I can not fire the click events. Some day ago I write another widget and it worked perfectly and still does, but not this example.

I send you the code.

Thanks

Cesar

Hi,

I solved the problem, I had two layers with the same name. It seems that every project must have different names for the elements: layouts, service mudule, etc

Thanks

Cesar
 

demasi

Active Member
Licensed User
Longtime User
Hello, I'm trying to make a widget in B$A 4.30, I tried Erel's example, but in my Sony Xperia Z3 with Android 5.02 the widget does not appear in the launcher, so I cant install it to screen. I tried in another phone, samsung note4 with android 5 and it worked as a charm.
all widgets I've installed in my Sony from Google Play worked with no problems.
can someone give some tip to solve this?
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
I think that the service doesn't start... I don't see it in the log.
Is it possibile? How can I check this?
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
When you put the widget on the Launcher's screen, it should start. You should see that in the logs.
If you want to check that directly in the system, you should see in the Android settings \ Apps \ Currently running your app's icon and the name of the service
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
But the widget isn't created on the widgets list
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
So please could you check in \Objects\res\xml that a XML file exists for the widget ? Its name should be : [your widget's service name]_info.xml
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
So please could you check in \Objects\res\xml that a XML file exists for the widget ? Its name should be : [your widget's service name]_info.xml

Yes.. It has got the same name of the service + _info.xml
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
And of course, in Service_Create you have used the ConfigureHomeWidget(layout, event, refreshtime, widget's name,false). If yes, sorry, I won't be able to help more. Only Erel and experts could
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…