You can see the basics by downloading Tic-tac-toe from the Demos menu.
As Symbroson implied, the only practical way to achieve what you seem to be describing is to use some sort of server on the internet that both devices can connect to.
Back in 2014, Jorge posted a wonderful example https://groups.google.com/d/msg/androidscript/BPkAp3AWpxg/1CVXlgqeOb8J but firebase made some major changes later and that approach is no longer available.
It would be really great if someone could find the time to build a firebase example that works with the latest version of firebase.