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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:36:10+00:00 2026-06-12T10:36:10+00:00

All I want to do is start the wake_lock with one button and end

  • 0

All I want to do is start the wake_lock with one button and end it with another. It’s to use in a larger app I’m creating but this is the part I’ve been having trouble with. I’ve looked on this site and others and found the exact same codes for all but its not working for me so – what am I doing wrong?

My Java Code:

package com.example.tester_app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class TestMain extends Activity {

PowerManager.WakeLock wl;
Button bstart, bstop;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView (R.layout.main);

    //Views from xml
    bstart = (Button) findViewById (R.id.bStart);
    bstop = (Button) findViewById (R.id.bStop);


    //power manager for wake lock..
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");


    bstart.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            Toast.makeText(TestMain.this, "started", Toast.LENGTH_SHORT).show();
            wl.acquire(); //keeps cpu from sleeping
        }
    });

    bstop.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Toast.makeText(TestMain.this, "stopped", Toast.LENGTH_SHORT).show();
            wl.release();
        }
    }); 
}
}

My XML Code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >

<Button
    android:id="@+id/bStart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start" />

<Button
    android:id="@+id/bStop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="12dp"
    android:text="Stop" />

</LinearLayout>

My Manifest Code:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tester_app"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission>



<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Main"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
  • 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-12T10:36:12+00:00Added an answer on June 12, 2026 at 10:36 am

    Looks like the name of your Activity class is different from the name you’ve given in the manifest (TestMain vs Main). Make sure they’re both the same.

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

Sidebar

Related Questions

Basically I want start a few threads which execute serially one after the another.
Hi all I want to start Android development but I just don't like Eclipse.
in linux, let say i want to start tomcat, and want to direct all
All I want is a one pixel black border around my white UILabel text.
First of all, I don't want to start a coding styles war, so please
Just want to start out by saying this seems like a great site, hope
First of all i want to start off by saying I'm kind of a
I have some testcases for a program, so i want to start all of
All I want to do is just clear the text box on a button
first of all I want to apologize about Title. I have one winform which

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.