Я создаю простой Android-виджет, в котором будут кнопки, открывающие различные действия в приложении.Android Widget With Buttons, Remove Update
public class ExampleAppWidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
Log.i("ExampleWidget", "Updating widgets " + Arrays.asList(appWidgetIds));
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intentForHome = new Intent(context, WidgetExampleActivity.class);
PendingIntent pendingIntentForHome = PendingIntent.getActivity(context, 0, intentForHome, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget1);
views.setOnClickPendingIntent(R.id.button, pendingIntentForHome);
// Create an Intent to launch Second Activity
Intent intentForSecond = new Intent(context, SecondActivity.class);
PendingIntent pendingIntentForSecond = PendingIntent.getActivity(context, 0, intentForSecond, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
views.setOnClickPendingIntent(R.id.button2, pendingIntentForSecond);
// Tell the AppWidgetManager to perform an update on the current app
// widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
Это работает и открывает правильную деятельность с помощью каждой кнопки. Но мне просто интересно, что такое updatePeriodMillis для. Мне не нужно ничего в виджетах обновлять и просто хочу, чтобы кнопки открывали приложение. Могу ли я избавиться от частей обновления. Я не хочу, чтобы мое приложение продолжало обновлять виджет.
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="10000"
android:initialLayout="@layout/widget1">
</appwidget-provider>
также это правильный способ выполнения кликов кнопки из виджета. В некоторых учебниках я вижу, что это делается по-другому? Спасибо.
Dublate: http://stackoverflow.com/questions/5641134/how-to-disable-widget-updateperiodmillis –