Hi VodkaWine, I'm no kind of expert with AppWidgets; I'm still working on my first one. But I'm happy to share what I have learned along the way.
First, your code is structured quite differently than mine. That doesn't mean that either of us is wrong, but it does mean that yours may simply work differently. I modeled mine after the AppWidget in the API demos; I have my code split into separate onEnabled and onDisabled event handlers, with a separate class for receiving other events (like TIME_CHANGED, or the pseudo-TIME_TICK). As I understand it, your approach of using a single onReceive event handler is just as valid, and looks like it's cleaner than mine. But again, it does mean that my advice won't be exactly applicable to you. Second, you have your code set up to create a new alarm listener on every onUpdate. As shown in my July 8 posting, I use 2 alarm handlers: a one-shot to get the pseudo-TIME_TICK aligned with the RTC minute, then a repeating one for every minute after that. I don't know which approach is better, again. I can't see why yours wouldn't work, but neither can I say for sure that it will. Third, you said you tried the intent-filter approach, but then moved to this alarm-based one. Something I am sure of is that you need both; you can't use the TIME_TICK intent, but you still need TIME_CHANGED (and probably TIMEZONE_CHANGED) to handle those "unusual" cases, in addition to your alarm for the "usual" case of updating every minute. It doesn't look hard to integrate into your current code - should just be a couple more actions to test for in your onReceive - but again, my approach is different. Beyond those observations, I can't see anything actually wrong with your code. I would say that my approach does seem to work with multiple AppWidget instances on the home screen, though, so if you can't find what's wrong with yours, you might consider trying mine. String On Jul 31, 11:29 am, VodkaWine <vodka....@gmail.com> wrote: > Dear String : > > I want to implmement a digital clock like in the following link. > > http://retroclock.jsource.nl/ > > But I have problem in digital clock which synchronize with system > time. > > I use the intent-filter originally, but the method seems impossible. > > filter.addAction(Intent.ACTION_TIME_TICK); > filter.addAction(Intent.ACTION_TIME_CHANGED); > > I reference your methods, but still fail. Please help me. > > In the following, attached my source code method - onReceive(Context > context, Intent intent) > > -------------------------------------------------------------------------- > public static PendingIntent sender = null; > public static AlarmManager am = null; > > public void onReceive(Context context, Intent intent) { > > super.onReceive(context, intent); > > String action = intent.getAction(); > > if (action.equals("android.appwidget.action.APPWIDGET_UPDATE")) { > > // First alarm to go off when the RTC minute changes > long firstTime = System.currentTimeMillis(); > firstTime += (60000 - firstTime % 60000); > > // Schedule the alarm > sender = PendingIntent.getBroadcast(context, 0, intent, 0); > am = (AlarmManager)context.getSystemService > (Context.ALARM_SERVICE); > > am.set(AlarmManager.RTC, firstTime, sender); > // am.setRepeating(AlarmManager.RTC, firstTime, 60000, > sender); > } > > if (action.equals("android.appwidget.action.APPWIDGET_DISABLED")) > { > if(am != null && sender != null) { > sender.cancel(); > am.cancel(sender); > } > am = null; > sender = null; > }} > > -------------------------------------------------------------------------- > > The above code can work when only "one widget" be put in Android > Launcher Desktop. > > If more than two widget, it will have problem. > > I use this method, this still have other problem about TIME_Change by > manaul setting. > > Please assist me ! Thank you very much . > > VodkaWine --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---