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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:25:11+00:00 2026-06-15T20:25:11+00:00

How to get log at run time when force close in Android application. I

  • 0

How to get log at run time when force close in Android application.
I want to get logs and mail it.

  • 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-15T20:25:12+00:00Added an answer on June 15, 2026 at 8:25 pm

    Here some code to collect logs inside application:

        private int MAX_LOG_MESSAGE_LENGTH = 100000;
        private String[] mFilterSpecs;
        private String mFormat;
        private String mBuffer;
    
    private class CollectLogTask extends AsyncTask<ArrayList<String>, Void, StringBuilder> {
        @Override
        protected void onPreExecute() {
    
        }
    
        @Override
        protected StringBuilder doInBackground(ArrayList<String>... params) {
            final StringBuilder log = new StringBuilder();
            try {
                ArrayList<String> commandLine = new ArrayList<String>();
                commandLine.add("logcat");//$NON-NLS-1$
                commandLine.add("-d");//$NON-NLS-1$
                ArrayList<String> arguments = ((params != null) && (params.length > 0)) ? params[0] : null;
                if (null != arguments) {
                    commandLine.addAll(arguments);
                }
    
                Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    log.append(line);
                    log.append(LINE_SEPARATOR);
                }
            } catch (IOException e) {
                Log.e(TAG, "CollectLogTask.doInBackground failed", e);//$NON-NLS-1$
            }
    
            return log;
        }
    
        @Override
        protected void onPostExecute(final StringBuilder log) {
            if (null != log) {
                // truncate if necessary
                int keepOffset = Math.max(log.length() - MAX_LOG_MESSAGE_LENGTH, 0);
                if (keepOffset > 0) {
                    log.delete(0, keepOffset);
                }
    
                if (mAdditonalInfo != null) {
                    log.insert(0, LINE_SEPARATOR);
                    log.insert(0, mAdditonalInfo);
                }
                              Log.d("printLog",log.toString());
    
            }
        }
    }
    

    Now call this async class like this.

        ArrayList<String> list = new ArrayList<String>();
    
        if (mFormat != null) {
            list.add("-v");
            list.add(mFormat);
        }
    
        if (mBuffer != null) {
            list.add("-b");
            list.add(mBuffer);
        }
    
        if (mFilterSpecs != null) {
            for (String filterSpec : mFilterSpecs) {
                list.add(filterSpec);
            }
        }
    
        new CollectLogTask().execute(list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a while, every time I try to run an Android application project, get
I'm analyzing an iOS 4 application for iPhone and I get this log: Leaked
I get many normal log lines in my google app engine application. But today
I want to get a detailed log about my stack trace. I can get
I edited the code the way @CommonsWare told me i get force close when
I'm getting this run-time error and I'm really struggling to get to the bottom
I have two process that running at random time and I want to force
I get the SIGSEGV - Segmentation Fault on the run-time for the code below
If I console log test I get [ { property_1: a, property_2: b, }
I get an 500 internal server error and in the log files it writes:

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.