Engaging in mentally stimulating activities throughout life is associated with better cognitive function/thinking ability. Almost any type of mental activity could be beneficial, but the activities should be done regularly and involve new learning and be reasonably complex (e.g. learn a new language).
Physical activity throughout life can help prevent cognitive decline and dementia. Physical activity has other health benefits too e.g. cardiovascular.
Managing your heart health, particularly in midlife, can help reduce your risk of developing dementia. Conditions like high blood pressure, high cholesterol, diabetes and obesity can increase your risk of developing dementia.
Be socially engaged. Being socially active may benefit your brain health too. Stay connected to family and friends, join a club or group or consider volunteering.