Mono for Android (C#) を使用してシンプルなホームスクリーン ウィジェットを作成するためのチュートリアルはありますか? 公式サイトには、ウィジェットのコードのみがあり、チュートリアルはありません。私がやりたいのは、ウィジェットにテキストを書き込んで x ごとにテキストを更新することだけです。
1089 次
1 に答える
0
updatePeriodMillis 属性値を設定すると、onUpdate メソッドがその期間で正確に呼び出されることが保証されないため、AlarmManager を処理する必要があります。
https://github.com/xamarin/monodroid-samples/tree/master/SimpleWidgetから、 onUpdate を次のように置き換えます。
private PendingIntent service = null;
public override void OnUpdate (Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
//// To prevent any ANR timeouts, we perform the update in a service
//context.StartService (new Intent (context, typeof (UpdateService)));
AlarmManager m = (AlarmManager) context.GetSystemService(Context.AlarmService);
Intent i = new Intent (context, typeof (UpdateService));
if (service == null)
{
service = PendingIntent.GetService(context, 0, i, PendingIntentFlags.CancelCurrent);
}
m.SetRepeating(AlarmType.Rtc, 0, 1000 * 3, service);
}
次に、サービスで:
WordEntry entry = new WordEntry() { Title = "test", Description = DateTime.Now.ToLongTimeString() };
ウィジェットは 3 秒ごとに時間を更新します。
お役に立てれば。
于 2012-11-26T10:38:21.107 に答える