2016-08-28 1 views
5

Android 앱에서 지연된 후 일부 코드를 표시하려고합니다. 나는 C 번호와 Xamarin.Android에서이 작업을 수행하려면 어떻게Xamarin Android에서 지연 후 코드를 실행하는 방법

new Handler().postDelayed(new Runnable() 
{ 
    @Override 
    public void run() 
    { 
    // your code that you want to delay here 
    } 
}, 1000/* 1000ms = 1sec delay */); 

:이 작업을 수행하는
자바 코드는 다음과 같이인가?

답변

12

이 작업을 시도 할 수 있습니다 :

Handler h = new Handler(); 
Action myAction =() => 
{ 
    // your code that you want to delay here 
}; 

h.PostDelayed(myAction, 1000); 

document

+0

감사합니다. 이 인스턴스에서 어떻게 구현할 수 있는지 알고 계십니까? http://stackoverflow.com/questions/39124434/animate-recyclerview-items-one-by-one? – amitairos

1

에서 봐 난 당신이 AdvancedTimer 같은 크로스 플랫폼 타이머를 사용하는 것이 좋습니다. 확인 : github repo

API 사용

단순히 종속 서비스를 사용 Timer 클래스에 액세스하려면 :

IAdvancedTimer timer = DependencyService.Get<IAdvancedTimer>(); 

당신 MUST 타이머 초기화 initTimer 전화;

timer.initTimer(3000, timerElapsed, true); 

initTimer(interval, Eventhandler function, AutoReset); 

방법

timer.startTimer(); 

timer.stopTimer(); 

timer.getInterval() 

timer.setInterval(5000); 

timer.isTimerEnabled(); 
+0

감사합니다. 이 인스턴스에서 어떻게 구현할 수 있는지 알고 계십니까? http://stackoverflow.com/questions/39124434/animate-recyclerview-items-one-by-one? – amitairos