Dumpsys-like functionality for apk app

后端 未结 1 1970
误落风尘
误落风尘 2020-12-17 06:29

I am looking for a solution to access the internal state of our app from adb for debugging purposes. I have used dumpsys a lot to get the internal state of system services

相关标签:
1条回答
  • 2020-12-17 07:09

    in your Activity override dump() method, for example:

    @Override
    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
        //super.dump(prefix, fd, writer, args);
        writer.println();
        writer.println("command line arguments:");
        writer.format("length: %d, args: %s", args.length, Arrays.toString(args)).println();
    }
    

    then start your Activity and type in the terminal:

    adb shell dumpsys activity top your cmd line arguments

    or:

    adb shell dumpsys activity top

    if you don't want to pass any arguments to dump() method

    the same method exists in other components like Service or ContentProvider - see their official documentation on how to invoke them by using adb shell dumpsys activity command, also there are classes that have their dump() methods that can be used to dump their internal state - for example ApplicationInfo, ActivityInfo, Looper, Handler, Binder, Fragment and many others

    0 讨论(0)
提交回复
热议问题