Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6105585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:59:13+00:00 2026-05-23T13:59:13+00:00

I am working on Android 3.0 and I need to know in my application

  • 0

I am working on Android 3.0 and I need to know in my application when the device goes on sleep / turn off screen.

How can I register to this intent/event so I will be able to run some actions when this happens? Is there any action in BroadcastReceiver that notifies for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:59:14+00:00Added an answer on May 23, 2026 at 1:59 pm

    This page has a tutorial on exactly what you’re looking for.

    Code copied from that page (in order to turn this from a link-only answer to something directly useful):

    1) Create a class in your application to receive the intent. For example, the following receiver stands alone and sets a static variable to be used in part 2:

    public class ScreenReceiver extends BroadcastReceiver {
        public static boolean wasScreenOn = true;
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                // do whatever you need to do here
                wasScreenOn = false;
            } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                // and do whatever you need to do here
                wasScreenOn = true;
            }
        }
    }
    

    2) Modify your activity to receive screen on/off events. Your receiver will check the static variable in your broadcast receiver to know the reason for the intent you just received:

    public class ExampleActivity extends Activity {
       @Override
        protected void onCreate() {
            // initialize receiver
            IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
            filter.addAction(Intent.ACTION_SCREEN_OFF);
            BroadcastReceiver mReceiver = new ScreenReceiver();
            registerReceiver(mReceiver, filter);
            // your code
        }
    
        @Override
        protected void onPause() {
            // when the screen is about to turn off
            if (ScreenReceiver.wasScreenOn) {
                // this is the case when onPause() is called by the system due to a screen state change
                System.out.println("SCREEN TURNED OFF");
            } else {
                // this is when onPause() is called when the screen state has not changed
            }
            super.onPause();
        }
    
        @Override
        protected void onResume() {
            // only when screen turns on
            if (!ScreenReceiver.wasScreenOn) {
                // this is when onResume() is called due to a screen state change
                System.out.println("SCREEN TURNED ON");
            } else {
                // this is when onResume() is called when the screen state has not changed
            }
            super.onResume();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a on-screen keyboard for Android, and I need to recognize
I am working on an Android Launcher application. I can host AppWidgets and display
I am working on an Android application (I will call this ProjectA) that is
I'm working with Android and I really need a fast way to get a
I am working on an Android service. I need to call RecognizerIntent from a
I'm working on a client-server Android application and trying to figure out how to
I'm working on an android application, and test it on an emulator, because I
I am working on an Android application which is supposed to play videos over
I am working on an Android application in which I want to integrate foursquare
I am working on an android application, where there are 4 activities. Activity1 is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.