私は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で偽としてそれを宣言することだし、それ以降、私はoncreate()
で真のそれを設定していboolean
である要求たとえば変数(ピックアップ、目的地、要求された)です。..ハンドラーでは、trueとfalseの間で5秒ごとに値が変化します(これは新しい値と古い値の間の平均です)。他の2つの変数と同じことです。
これは私の完全なコードです: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
ok私は主な質問にそれを追加します。 –