Sreejith Sree
Sreejith Sree

Reputation: 3681

Xamarin Forms: How to capture the time spend on a page

I need to capture the time a user spends on a page in my application.

I wish the time is in hour: minutes: seconds.

Using this I can track the user activities. I do some research but didn't found anything useful.

Is there any way to track the time a user spends on a page?

Upvotes: 0

Views: 200

Answers (1)

Jason
Jason

Reputation: 89102

use a Stopwatch

Stopwatch timer;

protected override void OnAppearing()
{
  timer = new Stopwatch();
  timer.Start();
}

protected override void OnDisappearing()
{
  timer.Stop();
  TimeSpan ts = timer.Elapsed;

  string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}",
            ts.Hours, ts.Minutes, ts.Seconds);
}

Upvotes: 3

Related Questions