I am doing an app with widget. The main idea is that user opens app, inserts credentials, app is closed and started an IntentService (kind of Cronos) witch update widget if there are new data received from server. Everything is working fine but when rotate screen all data from widget RemoteViews goes away and it apears again only those updated. I found some answers but need something cleaner.
Is there a trick to prevent changing orientation like in activity???
Note that I don't need to disable System ACCELEROMETER_ROTATION like:
Settings.System.putInt(getApplicationContext().getContentResolver(),Settings.System.ACCELEROMETER_ROTATION,0);
I supose that I need to change logical part of updating RemoteViews, at the moment I use smth like:
//fill up blok widget
public void fillUpBlockWidget(Context context, String blokTitle) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteViews.setTextViewText(resourceTitle, blokTitle);
ComponentName myWidget = new ComponentName(context, WidgetProvider.class);
AppWidgetManager.getInstance(context).updateAppWidget(myWidget, remoteViews);
}
and my WidgetProvider
class:
public class WidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
appWidgetManager.partiallyUpdateAppWidget(appWidgetId, views);
pushWidgetUpdate(context, views);
}
}
}