aakash2310

Untitled

Sep 23rd, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. package com.prem.fourtyone;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  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. // Live Template
  13.  
  14. private static final String TAG = "MainActivity";
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. }
  20. public void startThread(View view)
  21. {
  22. RunnableThread mythread = new RunnableThread(10);
  23. new Thread(mythread).start();
  24. // Thread t = new Thread(myThread);
  25. }
  26.  
  27. public void stopThread(View view)
  28. {
  29.  
  30. }
  31.  
  32. //Implement Thread uisng Runnable interface
  33.  
  34. public class RunnableThread implements Runnable
  35. {
  36. int seconds;
  37. RunnableThread(int sec)
  38. {
  39. seconds = sec;
  40. }
  41. @Override
  42. public void run()
  43. {
  44. for(int i=0; i<seconds; i++)
  45. {
  46. Log.d(TAG,"startThread : " + i);
  47. }
  48. try {
  49. Thread.sleep(1000);
  50. } catch (InterruptedException e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment