| 遅延処理のサンプル 
 「postDelayed」を使用して遅延処理を行っているサンプルです。
 
 
 
   
 
 
| import android.support.v7.app.AppCompatActivity; import android.os.Bundle;
 import android.os.Handler;
 
 //画面遷移のため
 import android.content.Intent;
 import android.os.Build;
 //ログを出力するため
 import android.util.Log;
 
 public class MainActivity extends AppCompatActivity {
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 
 getCurrentVersion();
 
 Handler handler = new Handler();
 handler.postDelayed(new testHandler(), 2000);
 }
 private  void getCurrentVersion()
 {
 int iVersion=0;
 iVersion=Build.VERSION.SDK_INT;
 Log.d("Build.VERSION.SDK_INT", String.valueOf(iVersion));
 }
 class testHandler implements Runnable
 {
 public void run()
 {
 Log.d("testHandler run","--------------------");
 //次の画面に移動します。
 Intent intent = new Intent(MainActivity.this,nextScreen.class);
 startActivity(intent);
 //この画面は閉じます。
 MainActivity.this.finish();
 }
 }
 }
 
 
 |  
 Handlerでオブジェクトを生成します。
 (例)
 Handler handler = new Handler();
 「postDelayed」で実行したい内容及び待ち状態の時間を設定します。
 (例)
 handler.postDelayed(new testHandler(), 2000);
 
 このサンプルでは待ち時間を過ぎると次の画面に移動させています。
 
 実行結果
 
 
   
 
 |  |