0

I've got an Android (News) Widget with a list of Elements and a Header.
Within this header, I've got a refresh button. If the user clicks the button the list gets updated.
The widget works fine. Refresh works and everything seems to be OK.
However, I've got one problem: If the user clicks on the refresh button multiple times the request gets sent multiple times as well. And that even while loading is still in progress.
I need to prevent any re-load while it is still loading. The problem seems that preventing within the onReceive method is too late.

Is there any possibility to hide/disable/... the refresh button while the app is still loading -> Important: Before sending the broadcast intent.

This is my code:

views.setOnClickPendingIntent(
    R.id.image_reload,
    context.pendingBrodcastIntent<NewstickerListAppWidgetProvider>(
        appWidgetId,
        NewstickerListAppWidgetProvider.ACTION_UPDATE_LIST
    )
)

I can hear the click sound if I click the refresh button.
I know it is possible because there is a different app, where it works as I would like it to work:
With the "DER SPIEGEL," you can hear the click sound only while the app is not refreshing. This means they block the sending broadcast pending intent with some mechanism: They are able to hide the refresh button after clicking it once, so a double tap is prevented.
enter image description here

1 Answer 1

0

Call setViewEnabled method just before the setOnClickPendingIntent solved my problem:

views.setViewEnabled(R.id.image_reload, canRefresh)
views.setOnClickPendingIntent(
    R.id.image_reload,
    context.pendingBrodcastIntent<NewstickerListAppWidgetProvider>(
        appWidgetId,
        NewstickerListAppWidgetProvider.ACTION_UPDATE_LIST
    )
)

I call the method updateAppWidgetList (where the code above lives in) twice.
First time with canRefresh set to false and one second later with canRefresh set to true.
This prevents clicking the refresh button twice within a second.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.