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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:02:26+00:00 2026-06-15T17:02:26+00:00

I have created a flashlight application…Everything is working fine…except that whenever the flashlight is

  • 0

I have created a flashlight application…Everything is working fine…except that whenever the flashlight is on and i press the back button…it remains on…and doesn’t stop…What to do?..I have used the onpause method but it doesn’t seem to work…

Also, I would be really grateful if someone could explain me the use of parameters. I have taken help from an online source for this program. I didnt understand the parameters method…Can someone explain it in detail?
Thanks In Advance….:)

My XML:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/aaaaaaa"
tools:context=".Flash" >

<ImageButton
    android:id="@+id/ib2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/ic_launcher" /></RelativeLayout>

My Flash.java:

    package com.potapptoes.flashlight;

    import android.os.Bundle;
    import android.os.PowerManager;
    import android.os.PowerManager.WakeLock;
    import android.app.Activity;
    import android.content.Context;
    import android.hardware.Camera;
    import android.hardware.Camera.Parameters;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.Window;
    import android.view.WindowManager;
    import android.widget.ImageButton;

    public class Flash extends Activity implements OnClickListener {
Camera cam = null;
ImageButton ib1;
Parameters para;
PowerManager pm;
WakeLock wl;

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "whatever");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    wl.acquire();
    initialize();
    ib1.setOnClickListener(this);
}

private void initialize() {
    // TODO Auto-generated method stub
    ib1 = (ImageButton) findViewById(R.id.ib2);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    if (cam == null) {
        cam = Camera.open();
        para = cam.getParameters();
        para.setFlashMode(Parameters.FLASH_MODE_TORCH);
        cam.setParameters(para);
    } else {
        para.setFlashMode(Parameters.FLASH_MODE_OFF);
        cam.setParameters(para);
        cam.release();
        cam = null;

    }
}

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

Manifest:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.potapptoes.flashlight"
android:versionCode="1"
android:versionName="1.0" >

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.potapptoes.flashlight.Flash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

  • 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-15T17:02:27+00:00Added an answer on June 15, 2026 at 5:02 pm

    You can try this

     para.setFlashMode(Parameters.FLASH_MODE_OFF);
            cam.setParameters(para);
            cam.release();
            cam = null;
    

    in your onpause or maybe in onBackPressed and see if it works.

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

Sidebar

Related Questions

I have created an android application that calls (using kSOAP library) a SOAP based
I have created a simple appmod that sends back the same message as it
I have created an app that suppose to toggle the button background color on
I have created a small daemon (basically a console application that hides the console
I have created some JQuery that will expand a div 'popup' on hover and
I have created a JSP / servlets application running in Tomcat 7. It runs
I have created a function that shows/hides different messages according to a combination of
I have created a dialog and got a problem that only part of the
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created a little program that reads in a Java file and feeds

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.