Note that there are some explanatory texts on larger screens.

plurals
  1. POFlashlight doesn't turn off when I press back button
    primarykey
    data
    text
    <p>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...</p> <p>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....:)</p> <p>My XML:</p> <pre><code> &lt;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" &gt; &lt;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" /&gt;&lt;/RelativeLayout&gt; </code></pre> <p>My Flash.java:</p> <pre><code> 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(); } } </code></pre> <p>Manifest:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.potapptoes.flashlight" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;uses-permission android:name="android.permission.CAMERA"/&gt; &lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.potapptoes.flashlight.Flash" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload