Writing activity with custom Fit field.

Good day!

Is it possible to write a FIT file with custom fields from my own application? 

In "samples" I found a Widget that's tracking an activity and a Data Field that's contributing custom fields.

But what should I do to start recording my own activity with my own data field from my own app? Is there some example? 

Thanks.