How to detect when an Android app goes to the background? onPause() works but it also called when orientation changed.
If orientation changes the app will call through the life cycle once again that means from oncreate
you can avoid it as well by writing the following to code to the manifest
<activity android:name="" android:configChanges="orientation|keyboardHidden|screenLayout|screenSize" android:label="@string/app_name" />
this tell the system that when orientation changes or keyboardHidden or screenLayout changes I will handle it by myself no need to re create it.
then write your code on on pause