简体   繁体   中英

Ads Changing for every 3-5 seconds in an activity of Android Application

I am developing one android application in which i have implemented the 10 ads in one activity using web services. Now, i want to give the timeline for changing those ads for every 3 to 5 seconds. Please help with the sample code/links. Thanks in advance.

just working with Countdown timer

Schedule a countdown until a time in the future, with regular notifications on intervals along the way. Example of showing a 30 second countdown in a text field:

new CountdownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
     }

     public void onFinish() {
         mTextField.setText("done!");
     }
  }.start();

Further more..

TimerTask.schedule() will solve your problem.

Please google for more information.

You should use AlarmManager or Timer service for doing it it is execute in every 3-5 second.

I have also make a function of using alarm manager auto logout if user ideal for 5 min then it is logout. public static void autoLogOut(Context context) {

    MyAlarmService.mContext = context;
    Intent myIntent = new Intent(context, MyAlarmService.class);
    pendingIntent = PendingIntent.getService(context, 0, myIntent, 0);

    AlarmManager alarmManager = (AlarmManager) context
            .getSystemService("alarm");

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, (5 * 60));
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            pendingIntent);

    // Toast.makeText(context, "Start Alarm", Toast.LENGTH_LONG).show();
}

it is execute after if user ideal for 5 min.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM