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 6680293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:27:28+00:00 2026-05-26T04:27:28+00:00

Im trying to do a simple broadcast in Android to detect the screen is

  • 0

Im trying to do a simple broadcast in Android to detect the screen is on. For me this is a learning excersize to understand the Android broadcast capabilities. Please help.
I have the Android XML

  <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".UsbddActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>


    <receiver android:name=".BootReceiver">
  <intent-filter>
            <action android:name="android.intent.action.SCREEN_ON"></action> 


  </intent-filter>
</receiver>
    </application>

The main Java file

package usb.usbd;
import android.app.Activity;
import android.os.Bundle;
public class UsbddActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        }
    }

The Broadcast class That supposed to display the toast.

package usb.usbd;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class BootReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context arg0, Intent arg1) {

        Toast.makeText( arg0, "worked", Toast.LENGTH_LONG).show();
        run(arg0 );

    }
    public void run(Context arg0 ) { 
          Toast.makeText(arg0, "sss", Toast.LENGTH_SHORT).show(); 
        } 


}

It doesnt dislay any errors nor does it display the toast. How can i get the toast to display when the screen is turned on.

  • 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-26T04:27:29+00:00Added an answer on May 26, 2026 at 4:27 am

    Have a look at this site: http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/

    First, unlike other broad casted intents, for Intent.ACTION_SCREEN_OFF and Intent.ACTION_SCREEN_ON you CANNOT declare them in your Android Manifest!

    You could handle this by gaining the ReceiveBootComplete Permission, then starting a service with the onBootReceiver, which registers the Intent Filter. Sounds complicated, but there is also a good example on this site.

    /edit: Ah, and I just saw that in the example it is done by onResume and onPause. It might be a way, but I wouldn’t recommend it. See this question: Service and a BroadCastReceiver
    It is explained there how to register a Receiver in your service.
    This link covers how to start a service on boot: http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across something like this in the AndroidManifest.xml: <receiver android:name=com.testco.test.TestReceiver/> The above is
I am just trying a simple application, to make the browser fullscreen. this is
I am currently trying to find a simple, easy way to publish/broadcast stock tick
I am trying a simple application where I have a mutable array of mutable
On Android, I am trying to send a custom broadcast message using a custom
Pulling my hair out on this one: I'm trying a simple redirect to home
I am trying to understand if I really have any case for using git/mercurial.
I´m trying this simple script: require 'prawn' template_file_name = File.join(File.dirname(__FILE__), 'template.pdf') pdf_file = Prawn::Document.new(:template
I'm trying this simple uni-directional one-to-one relationship Person ----> Address using many-to-one mapping with
I am new to this website and I am trying a simple inheritance example

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.