What's the best way to detect when a Home Screen Widget has gained or lost focus? An example of losing focus is if the user navigates to another screen or if another screen popped up in front of the Widget.
A:
From what I've seen of widgets there's no way of getting this sort of information.
Perhaps the best advice I could give is to come up with a way of doing what you need without this sort of information.
What is the reason you're trying to do it?
matto1990
2010-08-13 22:21:09
I want my service to asynchronously start an Activity, but to avoid being rude, only if the user is still on the home screen
zer0stimulus
2010-08-13 22:53:46
What if the user is looking at something on the home screen (like another widget)? Generally it's never a good idea to open an Activity if the user doesn't explicitly want it. You can try your best to guess when it might be convenient but it will always be unwelcome. What's the reason for wanting to open the activity?
matto1990
2010-08-13 23:02:15
It's an asynchronous button click. Essentially my widget will have ButtonA that when clicked on, will cause some background processing to be done via my Service. Usually, the operation is instantaneous and a results screen is spawned as if the widget launched the Activity. But in the case it takes a long time, it would be desirable to know if the user is still on the home screen before showing the results Activity.
zer0stimulus
2010-08-18 00:36:22
What a lot of apps with widgets do is when the refresh button is pressed, refresh the contents of the widget and show a summary of the results in there. If the user clicks on the widiget this is a sign to show the results in an activity. It takes a bit more programming but it gives an all round better user experience.
matto1990
2010-08-19 15:38:21