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.
Related
I have an reminder type of app that generates a full-screen notification via setFullScreenIntent when the alarm triggers. It works well.
The full screen activity is backed by a native XML that simply displays some text data from the passed intent. On top of it, I have a TextClock widget in default settings: so it simply displays a text clock with hours and minutes. This is similar to Android's default lockscreen.
What I found is that, if the user does not dismiss this notification (say the phone is just left aside in idle state), the existence of this full-screen activity with TextClock will rack up background time and usage percentage under Android's battery stats.
Now the full-screen activity does have showWhenLocked and turnScreenOn set, so it'd wake up the screen briefly. However, the screen does go back off very shortly without user action, because it does NOT use keepScreenOn.
I'd imagine the TextClock, being a native widget, should be fairly optimized and not cause any battery drain, especially when the screen is off and phone is idle. It should only need to update itself when screen is back on again.
But instead the phone seems to treat this as being running in background the entire time if not dismissed.
Any idea if this is normal, and if there's any way to optimize it without sacrificing the utility?
I have the following problem:
When the app is upgraded, the active home screen widget goes dead. It returns to the original XML layout before onUpdate() is ever called, and no longer receives broadcasts.
None of the overridden methods are ever called (onDeleted(), onEnabled(), onDisabled(), or onAppWidgetOptionsChanged()).
I have managed to reinitialize the widget once the app is opened, and leave the default text of the widget as "re-install widget" to inform the user.
However, there is a very important use case that is left out, specifically, when the user doesn't open the app after installing, but wants to use the widget (see the diagram).
Does anyone know a way to detect when the widget dies programmatically, without opening the app?
I know that the running widget code is from the old apk, but the fact that the widget doesn't actually die as soon as the app is installed, and the layout reverts back only when the home screen is navigated to tells me that there should be a way to "get in the middle of that."
Also, I know that the widget doesn't die right away because if the widget is reinitialized before it first dies (going to home screen), it won't have an effect. That is why the delayed thread is needed to reinitialize the widget when the app is closed.
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" />
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
Is there an Event that is fired when an widget becomes visible on to the homescreen. I didn't mean at install time, I mean if the user changes his homescreen by wiping the surface of the phone.
The background of this question is that I setup a timer in a service inside the widget that gets updates from a url but that should stop if the widget is not on the current homescreen.
Freudi
There is a way to do that, you can listen to Intent.ACTION_USER_PRESENT broadcast and update your widget on receiving the intent.
It will be fired when the user unlocks the home screen.
I am using it in my app and works great to update your widgets upon unlock.
No, sorry. There are dozens of home screen applications, some of whom may not even have the concept of "wiping the surface of the phone". A home screen is merely an activity with a particular <intent-filter>.
Not sure if this helps, but I stumbled across this..
WallpaperManager.setWallpaperOffsets() and WallpaperService.onOffsetChanged()
Perhaps you could use this? Set wallpaper offsets and use onOffsetChanged() to get current offsets?