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

  • Home
  • SEARCH
  • 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 6809325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:04:22+00:00 2026-05-26T20:04:22+00:00

I am working on the application,I am having the requirement:if user long press the

  • 0

I am working on the application,I am having the requirement:if user long press the power button at any time and press again to start device,the activity should start from where the device was shut down.I dont know either this is a valid question or not.
I tried working with:

public class PowerMangerTestActivity extends Activity {

private static PowerManager objpowermanager;
private static PowerManager.WakeLock wl;

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

}//end of onCreate
public void callTOWakeLock() {
    // TODO Auto-generated method stub
    objpowermanager=(PowerManager)getSystemService(Context.POWER_SERVICE);
    wl=objpowermanager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "******MyTag****");
    //You should acquire it when your app starts,
    if(wl.isHeld())
    {
        wl.release();
    }
    wl.acquire(); 

}
@Override
public void onDestroy() {
    wl.release();
}
@Override    
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();

}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    callTOWakeLock();
}
/*@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
        Intent i = new Intent(this, PowerMangerTestActivity.class);
        startActivity(i);
        return true;
        TextView tv=(TextView) findViewById(R.id.textview);
        tv.setText("You press power button");
    }

    return super.dispatchKeyEvent(event);
}*/

}
but not getting expected behaviour.
I have tried to catch KeyEvent.KEYCODE_POWER,but not getting how to use for this scenario.
any suggestions?
thanks

  • 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-26T20:04:22+00:00Added an answer on May 26, 2026 at 8:04 pm

    This may be unacceptable to you, but you should NOT DO THIS.

    It is going against a usability idea called “expected behavior”.

    You are doing something that a user is not expecting, and there is a good chance they are going to be pissed if you do this.

    Just my two cents!

    I would try and find another solution to this problem, such as caching useful data in phone storage, and recalling it when the application is resumed/started.

    onPause still should be called when the power button is long pressed. The only case (as far as I know) where it won’t be called is on a battery pull

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

Sidebar

Related Questions

I am working on JRuby on Rails Application having JRuby-1.6.7 and Rails 3.2.2 I
I have web application Project having RPC call. one RPC async is working fine.
I'm working on an application that consists of many modules, with some having dependencies
I'm having working on a Rails application that is supposed to run on an
I am having some problems getting a larger application with many table relationships working
I'm working on an ASP.NET application and I'm having difficulty in understanding why a
I am working with an ASP.NET MVC application. I have one master page having
I'm working on this drag and drop application with jquery/javascript, and I'm having to
I am working on server side application of FB login. Having converted the example
I'm working on Asp.net MVC3 web application. I'm having one page on which appx.

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.