Wear Os, Handling button events that spawns a new activity

axaaxa Member ✭✭✭
edited September 2018 in Xamarin.Android

The basis of this question is how to reliably debounce multiple button clicks, but the problem to me seems specifically on Wear OS.

Here are the details:

  • The button event handlers is intended to spawn a new Activity.
  • The originating activity will not be finished, it will remain 'paused' out of view.


  • If I do nothing, then as may be expected, 2 activities are spawned.
  • If I follow the popular advise online, timestamp the button clicks dismissing follow up clicks withing a certain time frame, the application goes out of view replaced with the watch face. Yet reentering the app, logic was property followed and a single lone new activity is visible.

I have also tried:

  • Disabling the event handler and replacing it in various ways.
  • Wrapping the event handler in a semaphore to prevent reentry.
  • Direct the button event handler off of the UI to a new worker thread.
  • all of the above
  • none of the above

Thing is, i find of the few apps I have on my watch by Google themselves to fail in the exact same ways.
When double tapped duplicate activities are spawned in Google Hangouts and Google Keep for example.
While the in the settings menu many of the items will exit to the Watch face when quickly double tapped, and some have multiple activities spawned.
The best behaving app i could find is Contacts, when selecting a contact, but that flickers and doesn't even seem completely right.
Are these just amateur apps as mine? Regardless it doesn't give me much hope im going to solve this issue, but counting on some of you may have.

Im only assuming these other apps are doing what I am in spawning a new activities on button click, they might well be doing something else
And I'm not suggesting any of these apps are made with Xamarin, or Xamarin is the issue, rather it does suggest to me that there is something fundamentally wrong. Or something wrong with my test device (ticwatch E). (though the emulator acts the same way)

Who out there has successfully solved this issue on Wear OS? How'd you do it?

bool Sema4;
long LastButtonClickTIme;

protected override void ListViewItemClick(object sender, AdapterView.ItemClickEventArgs args)
    if (!Sema4)  // a semaphore to prevent reentry
        Sema4 = true;
        ListView.ItemClick -= ListViewItemClick; // unassigning the event handler

        var now = SystemClock.ElapsedRealtime();
        if (now - LastButtonClickTime >= 1000)   // dismissing clicks within 1 second
            LastButtonClickTime = SystemClock.ElapsedRealtime();

            var intent = new Intent(this, typeof(RoomActivity));
            StartActivityForResult(intent, 0);

        ListView.ItemClick += ListViewItemClick;
        Sema4 = false;


  • axaaxa Member ✭✭✭
    edited September 2018

    Adding to the 'RoomActivity' intent:

    • intent.SetFlags(ActivityFlags.SingleTop);

    before starring the activity proved not to help

  • axaaxa Member ✭✭✭
    edited March 17


Sign In or Register to comment.