'Stop and block phone application when android auto is connected

how can we stop/block the application to open when we have a state of connected android auto. I can observe the state, I have the android auto app, but I would like to block to run the apps parallel to save resources and manage complexity (I wouldn't like to sync everything between the two).

Google maps behaviour with Android Auto:

The google maps shows a Toast when android auto is connected like: "Your phone can't display Google maps while Android Auto is running" and doesn't open (more precisely it opens and exit immediate)

Any idea how it's achieved? Killing MainActivity is an option? Is it a good practice?



Sources

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

Source: Stack Overflow

Solution Source