Welcome to

w3study.github.io




Topics

Handler in Hindi

Runnable in Hindi



Handler & Runnable in hindi (Development of Android applications)

Handler in Hindi

Basic Example of Handler in Android (Java)

java

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private Handler handler = new Handler(Looper.getMainLooper());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = findViewById(R.id.textView);

        // Background Thread
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000); // Simulate long task (3 sec delay)
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                // Update UI using Handler
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        textView.setText("Text Updated After 3 Seconds!");
                    }
                });
            }
        }).start();
    }
}

Code Explanation:

Output:

जब app launch होगी, तो 3 सेकंड बाद TextView का text "Text Updated After 3 Seconds!" में बदल जाएगा।

Runnable in Hindi

नीचे Runnable के उपयोग के कुछ उदाहरण दिए गए हैं:

1. Basic Runnable Example

java

class MyRunnable implements Runnable {
    @Override
    public void run() {
        System.out.println("Background task is running...");
    }
}

// इसे इस तरह use करें:
Thread thread = new Thread(new MyRunnable());
thread.start();

Code Explanation:

2. Anonymous Runnable Example

java

Thread thread = new Thread(new Runnable() {
    @Override
    public void run() {
        System.out.println("Running in background...");
    }
});
thread.start();

Code Explanation:

3. Runnable with Lambda Expression (Java 8+)

java

Thread thread = new Thread(() -> {
    System.out.println("Lambda Runnable is running...");
});
thread.start();

Code Explanation:



  • Async Task in Hindi

  • Development of Android Applications Notes in Hindi


  • Request:

    हैलो दोस्तों! उम्मीद करता हूं आपको हमारा यह content/post पसंद आया होगा। अगर आपको हमारा ये content/post पसंद आई हो तो अपने दोस्तों के पास भी share करे। और अगर आपको कोई problem या कोई specific content हिन्दी में चाहिए है तो आप हमें नीचे दिए गए Email या whatsapp number के जरिए बता सकते है।

    अगर आप CCC/diploma/polytechnic/MCA/BCA etc कर रहे है तो ये website स्पेशली आपके लिए ही है, जो student हिंदी में पढ़ाई करते है।

    Contact Us

    Email: deepanshuranjan8057@gmail.com

    Whatsapp: +91 8057754706



    Follow Us

    Facebook Logo    Instagram Logo