narimetisaigopi

MainActivity.java handlers

Feb 18th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package com.example.saigopinarimeti.helloworld;
  2.  
  3. import android.os.Handler;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.Button;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12. Button startHandler;
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_main);
  17.  
  18. startHandler = findViewById(R.id.startHandler);
  19.  
  20. startHandler.setOnClickListener(new View.OnClickListener() {
  21. @Override
  22. public void onClick(View v) {
  23. doDelay();
  24. }
  25. });
  26.  
  27.  
  28. }
  29.  
  30. void doDelay(){
  31. Log.d("doDeplay","doDeplay called ...");
  32. Handler handler = new Handler();
  33. handler.postDelayed(new Runnable() {
  34. @Override
  35. public void run() {
  36. Log.d("doDeplay","doDeplay is completed ...");
  37. }
  38. },5*1000);
  39. }
  40.  
  41. }
Add Comment
Please, Sign In to add comment