[英]Android - Trying to change the color of a bouncing ball every 3-5 seconds?
[英]Ads Changing for every 3-5 seconds in an activity of Android Application
我正在開發一個Android應用程序,其中我使用Web服務在一個活動中實現了10個廣告。 現在,我想給出每3至5秒更改這些廣告的時間表。 請幫助您提供示例代碼/鏈接。 提前致謝。
只是使用倒數計時器
安排倒計時,直到將來的某個時間,並在整個過程中定期通知。 在文本字段中顯示30秒倒計時的示例:
new CountdownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
}
}.start();
TimerTask.schedule()
將解決您的問題。
請谷歌了解更多信息。
您應該使用AlarmManager或Timer服務來執行它每3-5秒執行一次。
如果用戶理想5分鍾然后注銷,我還可以使用警報管理器自動注銷功能。 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();
}
如果用戶理想5分鍾后執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.