Hi !
I seem to have the same problem but the solution I've found everywhere on
the web and in this thread does not work for me :(
I posted my onUpdate method below, in which I perform a full initialisation
of a new RemoteViews object. Then I pass it to the AppWidgetManager. This
kind of operation (init + call to updateAppWidget) is done only in one
place in whole my application : in this onUpdate method. Thus, I never send
an incomplete RemoteViews object. This is why I don't understand why I
suffer from the same screen orientation change problem :'(
I tried to call the onUpdate method from the onReceive method, and it works
fine, but I think this solution is dirty, especially because I make this
additional call to onUpdate on every call to onReceive (I cannot filter on
some kind of "on screen orientation changed" message).
Here is the onUpdate method :
@Override
public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds) {
final RemoteViews remoteViews = new
RemoteViews(context.getPackageName(), R.layout.widget);
// Mise à jour de l'image dans les widgets
updateClockinImage(context,appWidgetIds, getCheckingCount(context));
// Build the intent to call the service
final Intent intent = new Intent(context.getApplicationContext(),
AddCheckingService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
// Pour réagir à un clic il faut utiliser une pending intent car le
onClickListener
// est exécuté par l'application Home
final PendingIntent pendingIntent =
PendingIntent.getService(context.getApplicationContext(), 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.btn_checkin, pendingIntent);
// Mise à jour des widgets avec le nouvel intent
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
Thanks in advance !!!
Le vendredi 14 janvier 2011 06:26:43 UTC+1, John Gaby a écrit :
>
> I have an App Widget on the Home screen which works fine until the
> screen is auto-rotated. At that point, the onClick connection (set up
> via a call to setOnClickPendingIntent) is lost. The only way I seem
> to be able to get it back is to delete the Widget from the Home screen
> and then add it back. Is there some kind of message that tells me
> that the screen has rotated that I need to respond to (and reestablish
> the connection)?
>
> Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en