Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.prem.fourtyone;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- public class MainActivity extends AppCompatActivity {
- // Live Template
- private static final String TAG = "MainActivity";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void startThread(View view)
- {
- RunnableThread mythread = new RunnableThread(10);
- new Thread(mythread).start();
- // Thread t = new Thread(myThread);
- }
- public void stopThread(View view)
- {
- }
- //Implement Thread uisng Runnable interface
- public class RunnableThread implements Runnable
- {
- int seconds;
- RunnableThread(int sec)
- {
- seconds = sec;
- }
- @Override
- public void run()
- {
- for(int i=0; i<seconds; i++)
- {
- Log.d(TAG,"startThread : " + i);
- }
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment