firstly the are connected but after ~5 seconds they disconnect and
stay paired.
If your device is Bluetooth low energy device, well, it is what Bluetooth LE designed to be. Unlike classical Bluetooth, Bluetooth LE keep connection for very short period of time. After data exchange complete, current connection end immediately. Connection will be established again when there is data to exchange next time.
If the problem isn't caused by Bluetooth designing then it should be caused by your code itself.
In your post we can see:
The application may be doing too much work on its main thread.
What this means is that your code is taking long to process and frames are being skipped because of it, It maybe because of some heavy processing that you are doing at the heart of your application or DB access or any other thing which causes the thread to stop for a while.
How to fix it?
The best way is to do all the processing no matter how small or big in a thread separate from main UI thread.
A comprehensive explanation is here.