Results 1 to 3 of 3
  1. #1
    jack12 is offline Member
    Join Date
    Oct 2016
    Posts
    22
    Rep Power
    0

    Default How to capture heap dump from Android App? 3 Options

    Here is the articles explains about How to capture heap dump from Android App? 3 Options

    https://blog.heaphero.io/2018/06/04/...app-3-options/

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,952
    Rep Power
    31

    Default Re: How to capture heap dump from Android App? 3 Options

    Do you have the source code for the code that is shown in an image for
    3. Capture Heap Dumps on OutOfMemoryError
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jack12 is offline Member
    Join Date
    Oct 2016
    Posts
    22
    Rep Power
    0

    Default Re: How to capture heap dump from Android App? 3 Options

    If you place the below code in your application, it will capture heap dumps whenever your application receives an OutOfMemoryError.
    Java Code:
    public class CaptureHeapDumps extends Application {
           private static final String FILE_NAME = "heap-dump.hprof";
           @Override
           public void onCreate() {
              super.onCreate();
    
    Thread.currentThread().setUncaughtExceptionHandler(OutOfMemoryException());
    
           }
           @NonNull
           private Thread.UncaughtExceptionHandler OutOfMemoryException() {
                   return new Thread.UncaughtExceptionHandler() {
                   @Override
                   public void uncaughtException(Thread t, Throwable e) {
                      String directory = getApplicationInfo().dataDir;
                      String absolutePath = new File(directory, FILE_NAME)
                             .getAbsolutePath();
                      try {
                          Debug.dumpHprofData(absolutePath);
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                   }
            };
        }
    }
    This would generate the heap dump file in this location: /data/user/0/appname/heap-dump.hprof
    Last edited by Norm; 07-20-2018 at 12:40 PM. Reason: Added code tags

Similar Threads

  1. how to capture java heap dumps? - 7 options
    By jack12 in forum Reviews / Advertising
    Replies: 0
    Last Post: 03-27-2018, 06:59 AM
  2. How to get thread dump
    By simorgh in forum Threads and Synchronization
    Replies: 0
    Last Post: 03-24-2010, 04:04 AM
  3. MySQL Dump
    By gilbertsavier in forum JDBC
    Replies: 0
    Last Post: 07-17-2009, 07:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •