How to be alerted when to get off the train?
Ask your railway company. Or your government. Or both.

The Dutch Railways (NS) has an app where you can plan train trips, but also get notifications when you need to check in and out and change trains, and realtime information about delays and schedule changes.

And since all Public Transport data is freely available in my country (and some others), there are other apps that can do the exact same.

So just search for the names of your transportation comnpanies in the Play Store, and see what you find. You may be surprised.