Bug 33494 - Give BroadcastReceiver a Action constructor
Summary: Give BroadcastReceiver a Action constructor
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: unspecified
Hardware: PC Windows
: Normal enhancement
Target Milestone: master
Assignee: Jonathan Pryor
Depends on:
Reported: 2015-08-30 08:27 UTC by Matthew Leibowitz
Modified: 2017-03-21 20:28 UTC (History)
2 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Matthew Leibowitz 2015-08-30 08:27:29 UTC
Often the BroadcastReceiver is just temporarily registered, so creating a new class that just has one line in OnReceive method is not always desired:

  mTimeZoneReceiver = new TimeZoneBroadcastReceiver (this);
  private class TimeZoneBroadcastReceiver : BroadcastReceiver
    private readonly WatchFaceEngine engine;
    public TimeZoneBroadcastReceiver (WatchFaceEngine engine)
      this.engine = engine;
    public override void OnReceive (Context context, Intent intent)
      engine.mCalendar.TimeZone = TimeZone.Default;
      engine.Invalidate ();

It would be much nicer to use:

  mTimeZoneReceiver = new TimeZoneBroadcastReceiver ((context, intent) => {
    mCalendar.TimeZone = TimeZone.Default;
    Invalidate ();

Note You need to log in before you can comment on or make changes to this bug.