spaceapi-community / my-hackerspace

Android app for hackerspaces status and information, using the SpaceAPI.
https://play.google.com/store/apps/details?id=io.spaceapi.myhackerspace
22 stars 3 forks source link

Very slow loading when adding widget to homescreen #23

Closed FriederHannenheim closed 1 year ago

FriederHannenheim commented 2 years ago

When I try to create a widget the app shows loading. I can tap the loading icon away but can't choose a hackerspace.

niccokunzmann commented 2 years ago

Could you say what you would like to see happening instead? I found that if I waited, the widget fills up.

FriederHannenheim commented 2 years ago

Oh. It loads for maybe a minute and then it works. Why does it load that long? Couldn't you just use the list of hackerspaces that is shown when you open the app normally?

niccokunzmann commented 2 years ago

Hm. This looks like several issues. Can you make a list for clarity?

dbrgn commented 2 years ago

Can confirm that loading seems to be very slow. If someone could debug (and maybe fix) the loading behavior, that would be very welcome.

niccokunzmann commented 2 years ago

Hm. I was looking at Widget.java, line 303.

https://github.com/spaceapi-community/my-hackerspace/blob/a05089e381e6167def804611975bd40a7ee4bae9/app/src/main/java/io/spaceapi/community/myhackerspace/Widget.java#L303

This appeared a while AFTER the widget was created. It seems that the UpdateService

https://github.com/spaceapi-community/my-hackerspace/blob/cd8e02d71651b2e31a2dbdbb3af00b43e4a53e69/app/src/main/java/io/spaceapi/community/myhackerspace/Widget.java#L287

is not used until it is triggered by some event.

In the AndroidManifest.xml we have this:

https://github.com/spaceapi-community/my-hackerspace/blob/cd8e02d71651b2e31a2dbdbb3af00b43e4a53e69/app/src/main/AndroidManifest.xml#L76

As well as the different receiver -> intent-filter:

My guess is that these trigger the update service. When the widget is first created, this does not take place.

Here is the update mechanism:

https://github.com/spaceapi-community/my-hackerspace/blob/cd8e02d71651b2e31a2dbdbb3af00b43e4a53e69/app/src/main/java/io/spaceapi/community/myhackerspace/Widget.java#L305

I would guess that once the widget is successfully created either

... Researching ....

https://developer.android.com/reference/android/appwidget/AppWidgetManager#summary


The most important AppWidgetProvider callback is onUpdate() because it is called wheneach App Widget is added to a host (unless you use a configuration Activity). Ifyour App Widget accepts any user interaction events, then you need to registerthe event handlers in this callback. If your App Widget doesn't create temporaryfiles or databases, or perform other work that requires clean-up, then onUpdate() may be the only callbackmethod you need to define. For example, if you want an App Widget with a buttonthat launches an Activity when clicked, you could use the followingimplementation of AppWidgetProvider:

According to this, my first guess was correct... Looking into it.

niccokunzmann commented 2 years ago

It seems to me that Widget_config calls updateAlarm and that creates the system alarm for update with a 50ms delay. This is but a rough estimation and might go wrong - it might not be updated after 50ms. That might be the problem here.

So, I had a look and I add the direct update without the redirection through the Android operating system... And it is there! Instantly....

PR in progress... #34

dbrgn commented 1 year ago

When adding the widget, the list of spaces needs to be loaded (in order to choose a space). Sometimes this is still slow, but there is an issue with loading of the directory that I'm currently investigating. It's probably an IPv6 issue on the directory server (which sometimes runs into a timeout, causing a 30-60 loading time).

However, the main issue was probably resolved with #34, so we can probably close this.