Issue
I'm working on inactivity detection.
I have successfully done so in iOS by subclassing UIApplication
and overriding SendEvent
as outlined here.
I know I could implement this separately for both iOS and Android, but I'd rather have a cross-platform Forms approach by intercepting all touch events and resetting my timers. I'd rather not have to add a touch event handler to all my pages either.
Solution
I was unable to find a cross platform approach. I was able to accomplish this by leaving the timer related information in core Forms project and implement the touch event handlers separately for iOS and Android. I handled the iOS touch events as outlined in the link in the OP, but for Android I took the approach of subclassing Activity
due to the presence of the OnUserInteraction()
method.
Initially I thought I would have to force Xamarin to use my subclassed Activity
for all pages that I use in Xamarin, but I was mistaken. AdamMeaney over on the Xamarin forums was able to help with providing a solution for the Android side of things with regards to subclassing an Android activity. As it turns out, Xamarin only uses one Activity
which inherits from Xamarin.Forms.Platform.Android.FormsAppCompatActivity
. I used the MainAcitivty
provided by Xamarin in the Droid project. From there, overriding the OnUserInteraction()
proved to be quite simple:
public override void OnUserInteraction()
{
base.OnUserInteraction();
//Do other stuff
}
Answered By - Timothy James
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.