Widget notification when homescreen app is restarted? - android

I'm developing a widget which gets updated via intents. However, when the homescreen app (tested with ADWLauncher EX, the default Android homescreen and HTC Sense) is restarted, the widget is displayed with it's default layout, and no notification event is received to update the widget's content. No widget added or widget updated events/intents seem to get fired.
Is there any way for a widget to get notified when the homescreen app is restarted and the widget is (re)displayed?
Thanks!

There may not be a reliable way to detect launcher restart on all platforms. I have seen ONLY com.sec.android.widgetapp.APPWIDGET_RESIZE on Samsung Touchwiz android 4.0.4, and ONLY android.appwidget.action.APPWIDGET_UPDATE_OPTIONS on Jellybean 4.1.1, and nothing on several other builds I tested.
That said, when I encountered a problem similar to what you describe, the root cause was improper use of RemoteViews. Check your code to ensure you are only using one instance of RemoteViews for all updates. If you are continually using a new instance of RemoteViews in your code, many of the updates to your appwidget will be lost the next time it restarts.
Similar question: Widget not updated on launcher restart

Related

What is the android lockscreen widget lifecycle?

I have an app widget and enabled it as a lockscreen widget by adding "keyguard" to the widgetCategory attribute of the app widget provider xml. I added a debug view to my widget to display a timestamp every time onUpdate is called.
I noticed that the lock screen widget sometimes gets updated several minutes before the home screen widgets do, even though my onUpdate iterates through all my widget instances. During these times, I noticed that my debug view shows no update in the timestamp for my lock screen widget instance, even though the data has been updated.
This leads me to believe some other callback is being invoked specifically for the lockscreen instance that is not for the home screen widget instances. What is the sequence of callbacks invoked for the lockscreen widget?
My second question is, with my device plugged in and log messages added in my code, why don't I see logcat messages consistently(android studio recognizes my device).
Additional details: KitKat 4.4.4, updatePeriodMillis in app widget provider is set to the minimum 30 minutes.

Amazon Hero widget retains information from previous application

When developing a sample list Hero widget application on the Amazon Fire phone I noticed that if I uninstall the application and install it again, the content from the previous application widget is displayed in the newly installed application.
Is this an expected behavior of the widget, because I cannot find any information about this?
The Amazon Fire phone just performed an update to a new operating system version(3.5.1) and after this update, the hero widget does not retain anymore information from the previous application.
It looks like this issue was fixed with the new system update.

Android Appwidget not showing in launcher after installation

Q. Android Appwidget not showing in launcher immediately after installation:-
What I have already tried and does not work consistently
Included stub Activity with MAIN and LAUNCHER intent filter
Included this code in onCreate() of this stub activity
sendBroadcast(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
What works consistently
Reboot
Change orientation of device with widget list opened. This causes a refresh of the widget list and shows the newly installed widget.
So is there something I am missing ? It creates poor perception when user installs widget and does not find the widget in the widget list. Generally leads to uninstall :(
This is an open issue for some devices and OS versions (mainly ICS it seems). What are you running? It should be the same issue which is, hopefully, soon fixed. I think the best option for you would be to inform your customers about this bug and that it is out of your hands. You should then also provide an easy way to fix it! An informed customer is less likely to have false expectations and uninstall your widget.

Is it possible to update RemoteViews of an Android widget if user is not at the Homescreen?

I'm working on an Android battery widget. I'm using the popular GeekYouUp Battery Widget source and everything works great, though I've noticed one problem which occurs even with the original source. If the user is running any application and the widget receives the broadcast, the update indeed happens and reads the state correctly, but the RemoteViews of the widget simply don't get updated. So when the user finishes the application and gets back to the Homescreen, the widget keeps showing the old battery state (the one from before starting the application).
I've tried creating a simple widget which updates some RemoteViews every few seconds and there's the same situation - everything works as long as the user is not running any application. Otherwise the RemoteViews don't get updated.
So, is it even possible to keep updating the RemoteViews on the Homescreen while an application is running, or does the system simply ignore them at that time?
Thanks in advance!
Actually, the widget is kind of independant from the app. It automatically updates itself (with updatePeriodMillis) :
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp" android:minHeight="72dp"
android:updatePeriodMillis="86400000" android:initialLayout="your layout" />

Android app Widget update new version removes the existing widget

I developed an APP + Home screen widget for Android. Now I updated the app (incremented the version code/name) but when i install, it doesn't automatically replaces the existing widget on screen. It just says "problem loading widget".
Any Idea??
Did you change the class name of the broadcast receiver implementing your widget? If so, don't do that.
There is of course the related use-case where there was a widget loaded on the home page and the user then uninstalls the application that contains the widget and widget config app. I guess this is the same as a new version which must to an uninstall/install cycle.
When that happens, all you see is the "Problem Loading Widget" in a toast-like box on the home screen. As far as I can tell, the widget gets no indicatation that the package is being uninstalled and I guess then the home screen AppWidgetManager thows up a default message.
Not well thought out behaviour on the part of the OS team. I suggest that it would be better to call the widget's onDisbled() and onDestroy() methods and to remove the widgets from the home screen before the package is removed so they can tidy up if need be and the user (non-geek phone user) gets a clean experience.
All I can find is the indication that only the user can remove a widget from the home screen, says commonsguy: Removing AppWidgets programmatically
I sure us developers can handle the odd weird toast, but for non technical "ordinary" phone users this sort of behaviour drives them back to iPhones very quickly.
This is the right behavior to me. As app is installed again, its widgets should be installed again too. If, for instance, there is a new activity to configure the widget, how do you know it as a user ?
There is, indeed, no way to guarantee that a new widget would run at all from this perspective.

Categories

Resources