0

I am trying to build my own launcher application with widget host support as described in Hosting widgets in an android launcher.

This is working fine with some widgets like Analog clock but its not working with the Digital clock widget. When I tried adding Digital clock it becomes invisible, whereas with default home launcher it works just fine. Also a few widgets like Note appear "partially" with this code. Not with the default launcher, it then works fine.

I am using Marshmallow and later versions of android, and the behavior is common to all the phones.

Please share if anyone faced this issue and found the root cause? Or point me in the direction to solve this.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I'm currently also working on a launcher application and having the same issue. Oddly enough it is working on older Android devices. Have you solved this issue? I have no idea what the issue could be at this point, since I followed the documentation. – jetspiking Feb 25 '20 at 20:32

1 Answers1

0

I finally found out the issue that causes this problem. Make sure you both have an onStart() and onStop() implementation (in which you start / stop listening) in your Activity (so not your fragment!). Also you should call "getActivity().getApplicationContext()" instead of "getActivity()" / "getContext()".

It is also important that you have a public AppWidgetHost and AppWidgetManager defined as a static variable in your Activity (this does not work in a fragment). You can access them by referencing them as public variables or creating static getters for them.

For any questions feel free to reply, since I was stuck on this for a day.

jetspiking
  • 304
  • 1
  • 5
  • I am getting following error java.lang.NullPointerException: getInstance(this.applicationContext) must not be null on line appWidgetManager = AppWidgetManager.getInstance(this.applicationContext). Please help to resolve – shripal Jun 23 '23 at 19:46