What comes first? Thought or electric activity?
There is ongoing electrical activity in the brain, there's even a lot of it when we are asleep when we are not 'thinking' at all, and also when we are unconscious and even when in coma. When brain activity does cease, i.e., its electrical activity becomes unmeasurable, there's a definite medical emergency.
Thus, there is unceasing activity in the brain. This activity includes both random 'noise' like neuronal jitter (Freeman, 1996) or constitutively active neuronal populations like those in the auditory (Wang &amp; Bergles, 2015) or optic nerves (Sernagor &amp; Grzywacz, 1996), as well as voluntary activity. In turn, the occurrence of random or controlled 'thoughts' is not so strange, as there is ongoing activation of neuronal pathways and activation in one neuron will trigger activity in others.
As a side note, and alluded to in the comments, thoughts are hardly voluntary; think psychotic patients who can experience their thoughts as intrusive or instructing them to do nasty things, people with OCD who have oppressing thoughts they have to do stuff, or folks suffering from PTSD who repeatedly experience flashbacks, nightmares and severe anxiety, as well as uncontrollable thoughts about the event.
As you say, all brain activity eventually boils down to ion gradients in the brain. Every cell in our body needs ion gradients to function properly for that matter.
What comes first? Activity or thoughts? Activity, because even random thoughts need a trigger to occur. How do these impulses come into being? Pre-existing activity.
References
- Freeman, Int J Neural Syst (1996); 7(4): 473-80
- Sernagor &amp; Grzywacz, Current Biology (1996); 6(11): 1503-8
- Wang &amp; Bergles, Cell Tissue Res (2015); 361(1): 65–75