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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:31:24+00:00 2026-06-05T08:31:24+00:00

for my app i want to stop the screen off function yes i just

  • 0

for my app i want to stop the screen off function

yes i just want to make it(Screen off function by pressing power button) disable that when user press power but and my app is running then screen must not off will give an toast message is it possible?

Goal :

  1. Disable auto screen timeout.

Done using this

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

used this post

now my first question is when my app will finish() time out will reset or screen will always on

2. Still using this user will be able to make screen off
My second question is

Can i prevent user to do this and instead of screen get off an alert message is shown

  • 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-06-05T08:31:25+00:00Added an answer on June 5, 2026 at 8:31 am

    In your Activity just add the following snippet:

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
            // do nothing but show a warning message
            Toast.makeText(this, "you pressed the power button",Toast.LENGTH_SHORT).show();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
    

    In case the above snippet doesn’t work,you can try this then:

    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
            //do nothing but show a warning message
            Toast.makeText(this, "you pressed the power button",Toast.LENGTH_SHORT).show();
            return true;
        }
    
        return super.dispatchKeyEvent(event);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a screen saver type app that needs to stop the user from
My app runs an NSTimer that updates the screen, but I want to stop
I want to make an app that has a view that moves randomly or
I want to stop outgoing call and open the application. The app is able
I want to use push notification in my app.i want to know that do
In my app I want a button which when pressed copies a file stored
In my app I want to display stop watch kind of thing i.e when
I want to implement a button that counts down when pressed. The idea is
in my app when user clicks on a spell button then it play audio
I have an MVC 2 app that I want all requests to return json.

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.