How to get current thread is interrupted in android?

AndroidMobile DevelopmentApps/Applications

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate How to get current thread is interrupted in android.

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
      android:layout_height="wrap_content" />

In the above code, we have taken textview. It contains information about the current thread is interrupted.

package com.example.myapplication;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
   TextView textView;
   protected void onCreate(Bundle savedInstanceState) {
      textView = findViewById(;
      textView.setText("Current thread: " + Thread.currentThread().isInterrupted());

Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run  icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −

In the above result, it returned false because the current thread is not interrupted.

Click here to download the project code

Published on 26-Mar-2019 17:47:49