Essayez ceci -
fichier Manifest -
(tous les 3 paramètres sont nécessaires pour gérer le changement d'orientation)
android:configChanges="keyboardHidden|orientation|screenSize">
fichier d'activité -
boolean isFirstTimeAdLoading = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rotate);
Log.e(TAG, "onCreate()");
if(isFirstTimeAdLoading)
{
// load ad
Log.e(TAG, "Ad Loaded for First Time");
// TODO : Call your Ad Loading Method here
// mark ad as 'already loaded once'
isFirstTimeAdLoading = false;
}
}
@Override
protected void onStart() {
super.onStart();
Log.e(TAG, "onStart()");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.e(TAG, "onConfigurationChanged()");
Log.e(TAG, "isFirstTimeAdLoading = " + isFirstTimeAdLoading);
}
Journaux -
06-12 14:44:15.900 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onCreate()
06-12 14:44:15.900 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: Ad Loaded for First Time
06-12 14:44:15.900 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onStart()
06-12 14:44:24.320 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onConfigurationChanged()
06-12 14:44:24.320 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: isFirstTimeAdLoading = false
06-12 14:44:26.070 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onConfigurationChanged()
06-12 14:44:26.070 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: isFirstTimeAdLoading = false
06-12 14:44:27.880 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: onConfigurationChanged()
06-12 14:44:27.880 11541-11541/com.example.futech.stackoverflowsamples E/RotateActivity: isFirstTimeAdLoading = false
Si vous voyez les journaux, vous saurez que onCreate
est appelé une seule fois, et chaque fois que les changements d'orientation après que est appelé, et donc, l'activité ne sont pas recréées chaque fois que vous faire pivoter l'écran (j'ai fait trois fois tourner mon appareil après le chargement initial).
Une telle situation de changement d'orientation, recrée votre activité. Vous devez gérer ce changement d'orientation –
votre activité doit gérer le changement d'orientation, pas admob. La diffusion d'une annonce interstitielle au démarrage de l'application est également interdite. Reportez-vous à ce lien https://support.google.com/admob/answer/6201362?hl=fr –