3
I am using google admob to place ads in my app, but I have some questions
- I can use the same ad block (id) for multiple Activity (each with a block)?
- How do I make the ad the first thing to load? the idea is that the time it takes the user to close the ad is the time to download the firebase database
My code (summarized):
public class MainActivity extends AppCompatActivity {
private InterstitialAd mInterstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, "ca-app-pub-5718158120252618~4586568420");
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
carregarAnuncio();
mInterstitialAd.setAdListener(new AdListener(){
@Override
public void onAdClosed() {
carregarAnuncio();
}
});
banco.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mInterstitialAd.show();
onibus.clear();
for(DataSnapshot data: dataSnapshot.getChildren()){
BusAdmin b = data.getValue(BusAdmin.class);
b.setKey(data.getKey());
onibus.add(b);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void carregarAnuncio() {
mInterstitialAd.loadAd(new AdRequest.Builder().build());
}
}
For now the ad is only loaded after the bank (firebase) want just the opposite