나는 handler.postDelayed()
메서드를 사용하여 시간 지연으로 작업을 반복합니다. 이것은 내 코드입니다.handler.postDelayed() 메서드의 문제
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void run() {
Toast.makeText(MapsActivity.this,pickup+" "+destination+" "+ Boolean.toString(requested),Toast.LENGTH_LONG).show();
}
}, 5000);
문제 내가 beggining에서 그것이 거짓 선언 해요 boolean
요청한 예를 들어 변수 (요청 된 픽업 대상)으로하고 그 후 나는 oncreate()
에서 진정한을 설정하려고 .. 처리기에서는 5 초마다 true와 false 사이의 값이 변경됩니다 (새 값과 이전 값 사이의 평균 임). 다른 두 변수와 동일한 것입니다.
이 내 전체 코드입니다 : handler.postDelayed (와
String pickup="/",destination="/";
Boolean requested=false;
int seats=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
if(getIntent().getExtras()!=null)
{
if(getIntent().getExtras().getString("class").equals("request")){
pickup = getIntent().getExtras().getString("pickup");
destination = getIntent().getExtras().getString("destination");
seats = getIntent().getExtras().getInt("seats");
if (!pickup.equals("")&&!pickup.equals("/")&&!destination.equals("")&&!destination.equals("/")&&seats!=0){
requested=true;
}
}
}
if (authenticate() == true) {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void run() {
Toast.makeText(MapsActivity.this,pickup+" "+destination+" "+ Boolean.toString(requested),Toast.LENGTH_LONG).show();
handler.postDelayed(this, 5000);
}
}, 5000); }}
해당 클래스의 전체 코드를 게시 할 수 있습니까? – RdlP
나는 주된 질문에 그것을 추가 할 것이다. –