Re-instantiate Home Screen Widget when App is Upgraded - android

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.

Related

What is the name of the cascading view of all apps in android home (see attached pic)?

When you click right most button in Andorid you see this
What is the name of this view?
When you swipe each app to right,
What happens?
What is the state of the activity (that was going
through) when you swipe it right)?
That is called the Overview Screen (aka recents screen, recent task list, or recent apps) - https://developer.android.com/guide/components/recents.html
When you swipe an app to the side and remove it from the list, it kills any background or empty processes the application is currently running, and then possibly kill the services that are running depending on if you set the onTaskRemoved() callback ( more info here: https://developer.android.com/reference/android/app/Service.html#onTaskRemoved(android.content.Intent) ). By default it does not remove any running services, though.
Things like Alarms, PendingIntents and Notifications will not be removed just by sliding the app closed in the overview screen. That only happens if a user does a force stop on the application (in the phones main Application Settings).
If the app was previously put into the background from pushing the home button or opening another app, then its state would be a background process and the last activity states in its lifecycle would be onPause() followed by onStop(), then when you swipe it to the side onDestroy() is called.

android access widget list, coax/remind users to install widget

I would like users to install the widget component of my app. Currently my "mainactivity" simply pops up a textview saying that there is a widget and to see their widget list.
Unfortunately right now, this requires them to open the mainactivity at all. If they want to see the widget in their list of widgets.
I don't want to do anything annoying, but there does seems like there are a lot of hurdles to actually getting and using a widget right now.
Things I could do: setup an onboot service that checks to see if the widget is on the launcher screen. It could remind users once or twice (ever) via some kind of notification. The widget can turn off that service using its onUpdate method or other lifecycle commands. I personally hate erroneous notifications.
One thing I'd like to do is programmatically open up the widgets list. is that possible? any other best practices? Since we can't have widget only apps anymore, I'd still like the main component of my app to be a widget.
setup an onboot service that checks to see if the widget is on the launcher screen
That will require the user to launch your activity, anyway, on Android 3.1+. Your "onboot service" will not run before then.
One thing I'd like to do is programmatically open up the widgets list. is that possible?
No. After all, the user has to indicate where on the home screen the app widget goes first.
any other best practices?
An app that is purely an app widget, unless it is blindingly obvious that it is only an app widget, is going to have these sorts of issues. That is why many app widgets are simply one piece of a more substantial app, so that if the user elects not to use your app widget, or does not notice that it is there, it is not that big of a deal.

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.

Remote service clean up, launcher screen refresh required

the problem is that once a widget of my application is uninstalled, it lkeaves a black message box on the home screen saying unable to load widget, i was wonderring if we could clean the system display our self, is it possbile to add some code/ call to instruct the android frame work to do that, the widget is being consumed by a remote service may be once service is finished/closed we can call some syetem calls, any code for helping out the home reloading will help, Thanks
There is nothing for you to do. The user and the home screen will take care of this.

Widget Update when user switches homescreen

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?

Categories

Resources