I have some activities and I have to display a fullscreen ad image before displaying the activity... all my activities extends a custom activity and I thought it was a great idea to implement that advertisement there, so I did:
public class BaseActivity extends Activity {
public void onCreate(Bundle icicle){
super.onCreate(icicle);
startActivity(new Intent(BaseActivity.this, InterstitialAdActivity.class));
}
}
And, the ad is displayed with this activity:
public class InterstitialAdActivity extends Activity{
@Override
public void onCreate(Bundle icicle){
super.onCreate(icicle);
TimerTask task = new TimerTask() {
@Override
public void run() {
InterstitialAdActivity.this.finish();
}
};
Timer timer = new Timer();
timer.schedule(task, 3000);
}
}
This works nice... the ad is displayed for 3 seconds and it closes automatically. The problem is that the activity that should be hide for the ad is being created faster, so the user can see it for a second before the ad is created. How can I avoid that behavior? How to make sure the ad activity starts before the another does?