'How can I enforce returning to my app when starting google navigation with an intent

I call Google Maps with an Intent like this:

Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + lat + "," + lon + "&mode=d"));
mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

Now I want to return to my app automatically when arriving at the destination. How can I achieve that?

Bonus question: Can I retrieve some information from Maps about the route like duration?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source