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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:02:31+00:00 2026-05-29T10:02:31+00:00

My android activity force closes at irregular times. All it is supposed to do

  • 0

My android activity force closes at irregular times. All it is supposed to do is turn on the LED torch. Here’s the error from the logcat:

D/CameraService(   70): CameraService::connect E (pid 4598, id 0)
I/CameraService(   70): cameraId:0
I/CameraService(   70): 2D mode only
W/CameraService(   70): CameraService::connect X (pid 4598) rejected (existing client).
D/AndroidRuntime( 4598): Shutting down VM
W/dalvikvm( 4598): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
E/AndroidRuntime( 4598): FATAL EXCEPTION: main
E/AndroidRuntime( 4598): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cakemansapps.lightwriter/com.cakemansapps.lightwriter.LightWriter}: java.lang.RuntimeException: Fail to connect to camera service
E/AndroidRuntime( 4598):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
E/AndroidRuntime( 4598):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
E/AndroidRuntime( 4598):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3288)
E/AndroidRuntime( 4598):    at android.app.ActivityThread.access$1600(ActivityThread.java:132)
E/AndroidRuntime( 4598):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1042)
E/AndroidRuntime( 4598):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 4598):    at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime( 4598):    at android.app.ActivityThread.main(ActivityThread.java:4263)
E/AndroidRuntime( 4598):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4598):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 4598):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 4598):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 4598):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 4598): Caused by: java.lang.RuntimeException: Fail to connect to camera service
E/AndroidRuntime( 4598):    at android.hardware.Camera.native_setup(Native Method)
E/AndroidRuntime( 4598):    at android.hardware.Camera.<init>(Camera.java:265)
E/AndroidRuntime( 4598):    at android.hardware.Camera.open(Camera.java:241)
E/AndroidRuntime( 4598):    at com.cakemansapps.lightwriter.LightWriter.onCreate(LightWriter.java:21)
E/AndroidRuntime( 4598):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
E/AndroidRuntime( 4598):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
E/AndroidRuntime( 4598):    ... 12 more
W/ActivityManager(  123):   Force finishing activity com.cakemansapps.lightwriter/.LightWriter
V/AgentService_J(30842): Action[1520]:com.htc.android.iqagent.action.ui03
I/HTC_SUBMITTER_C(30842): (-3) submitUI03:0,22,0,java.lang.RuntimeException: Fail to connect to camera service
V/AgentService_J(30842): (-3)ErrorCode:0,AppType:22,Level:0,Message:java.lang.RuntimeException: Fail to connect to camera service

Here’s my activity. There are no other classes.

package com.cakemansapps.lightwriter;
import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.view.KeyEvent;

public class LightWriter extends Activity implements OnTouchListener {
   private static final String TAG = "Touch" ;
   private Camera mCamera;
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      FrameLayout main = (FrameLayout) findViewById(R.id.main_view);
      mCamera = Camera.open();
   }

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                Log.w("LightWriter", "Down");
                setFlashlight(true);
            }
            else if (action == KeyEvent.ACTION_UP) {
                Log.w("LightWriter", "Up");
                setFlashlight(false);
            }
            return true;
        default:
            return super.dispatchKeyEvent(event);
        }
    }
/***
 * Attempts to set camera flash torch/flashlight mode on/off
 * @param isOn true = on, false = off
 * @return boolean whether or not we were able to set it
 */

public boolean setFlashlight(boolean isOn)
{
    if (mCamera == null)
    {
        return false;
    }
    Camera.Parameters params = mCamera.getParameters();
    String value;
    if (isOn) // we are being ask to turn it on
    {
        value = Camera.Parameters.FLASH_MODE_TORCH;
    }
    else  // we are being asked to turn it off
    {
        value =  Camera.Parameters.FLASH_MODE_OFF;
    }

    try{    
        params.setFlashMode(value);
        mCamera.setParameters(params);

        String nowMode = mCamera.getParameters().getFlashMode();

        if (isOn && nowMode.equals(Camera.Parameters.FLASH_MODE_TORCH))
        {
            return true;
        }
        if (! isOn && nowMode.equals(Camera.Parameters.FLASH_MODE_AUTO))
        {
            return true;
        }
        return false;
    }
    catch (Exception ex)
    {
    }
    return false;
}
    public boolean onTouch(View view, MotionEvent me) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
@Override
public void onBackPressed() {
    mCamera.release();
    this.finish();
    return;
   }
}

What did I do wrong?

  • 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-29T10:02:31+00:00Added an answer on May 29, 2026 at 10:02 am

    Do not save the Camera service connection in a field. Instead, call open when you are about to use the service and release when you are done.

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

Sidebar

Related Questions

I have an activity that force closes and i get a logcat error. It
When I start my (soon-to-be) android game (from eclipse) it opens, but immediately force-closes.
Here is my code import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import android.app.Activity; import android.os.Bundle;
In an given Android activity, I would like to start a new activity for
So I have a very simple android activity that starts a timer when you
I would like to implement the following simple pattern in an android app: Activity
I have an Activity in Android, with two elements: EditText ListView When my Activity
I'm trying to test an Activity in android which will show a ProgressDialog and
I have Activity A with android:launchMode=singleTop in the manifest. If I go to Activity
Does switching activities in Android start a fresh JVM? It seems like each activity

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.