Android 开发中,添加代码对Service 进行调试


介绍
调试 模式启动Android 项目时,在service 中设置断点,调试 器不会停止下来
解决方法
所有的这种情况下,都是在代码中声明。调用的方法是:

android.os.Debug.waitForDebugger();

举个例子,SoftKeyboard:

public class SoftKeyboard extends InputMethodService        implements KeyboardView.OnKeyboardActionListener {    @Override        public void onConfigurationChanged(Configuration newConfig) {        Log.d("SoftKeyboard", "onConfigurationChanged()");        /* now let's wait until the debugger attaches */        android.os.Debug.waitForDebugger();        super.onConfigurationChanged(newConfig);        /* do something useful... */      }

代码中你可以看到,首先是调用了日志记录器logger,代码运行到这里时,会将在logcat中添加一条记录,这是跟踪代码运行的一种方法,如果不需要在断点上停止时可以使用。但通常为了更详细的调试 ,这是不足够的。
第二条语句等待添加调试 器,添加了这条语句之后,可以在这个方法的任何地方添加断点。
Activity也是应用的部分时调试 Service 就更加容易了。那种情况下,首先需要启动Activity,调试 器也可以在Service 的断点中停止下来,不需要调用 waitForDebugger()。

更多相关文章

  1. Android(安卓)RadioGroup动态添加RadioButton,设置margin
  2. android TextInputLayout 更换系统自带眼睛图标
  3. 在Android中实现RN的自定义Native Modeule
  4. Android(安卓)RadioGroup设置单选效果
  5. 浅析移动开发
  6. 四、android studio使用自己库编译工程
  7. Arcgis api for android V2.0模拟器调试问题
  8. 【Android开发】完善搜索功能-添加最近查询字段
  9. android 动态调试 遇到的问题

随机推荐

  1. Android(安卓)显示Gif
  2. Android(安卓)BottomNavigationBar 底部
  3. 模拟按键操作的几种方式
  4. 解决adb shell 找不到设备的问题
  5. Android(安卓)中英文切换工具类
  6. Android(安卓)APK安装常见错误
  7. Android(安卓)NumberPicker 使用示例
  8. Android(安卓)打开资源raw文件
  9. ListActivity简介
  10. android resources web site