Suppose there is a command, how to make it appear at a certain period of time, for example, once a minute?

Ad.show(this, Ad.INTERSTITIAL); 

    1 answer 1

    I understand that we are talking about Android. If at once, a couple of solutions:

    1. Handler - we execute Runnable task in GUI stream periodically.
    2. ScheduledThreadPoolExecutor - perform a task in the background thread.
    3. ScheduledExecutorService .
    4. AlarmManager - we perform in the background, but with the help of services.
    5. TimerTask - unreliable thing, not recommended for use.

    Judging by the question, you want to display ads periodically or something like that, it means you have to do it in the GUI stream. Then the handler will do.

     private static const int DEF_INTERVAL = 500; private int mInterval = DEF_INTERVAL; private Handler mHandler; @Override protected void onCreate(Bundle bundle) { mHandler = new Handler(); startTask(); } Runnable mAdShower = new Runnable() { @Override public void run() { try { Ad.show(this, Ad.INTERSTITIAL); } finally { mHandler.postDelayed(mAdShower , mInterval); } } }; void startTask() { mAdShower.run(); } void stopTask() { mHandler.removeCallbacks(mAdShower); }