Reputation: 7636
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.
Upvotes: 1
Views: 442
Reputation: 4258
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.
Upvotes: 1
Reputation: 22066
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();
Upvotes: 2
Reputation: 15089
TimerTask.schedule()
will solve your problem.
Please google for more information.
Upvotes: 1