简体   繁体   English

如何使用Android App Widget进行调试?

[英]How to debug with Android App Widget?

For normal Activity, I can set some breakpoints and click F11 in Eclipse to debug. 对于普通的Activity,我可以设置一些断点并在Eclipse中单击F11进行调试。 However, it is not working when I develop app widget. 但是,当我开发app小部件时,它无法正常工作。 So, how can I debug? 那么,我该如何调试?

Here you can find a good answer: 在这里你可以找到一个很好的答案:

All you need to debug your widget code is almost same as what you do for normal applications. 调试窗口小部件代码所需的全部内容与您对普通应用程序的操作几乎相同。 Just follow the below steps: 只需按照以下步骤操作:

1. Press “debug” on the eclipse menu (or “run” it doesn't seem to matter) 1.在eclipse菜单上按“debug”(或“运行”它似乎没关系)

2. Once the widget apk is sync'ed and installed onto your emulator/device, switch your eclipse workspace to DDMS mode. 2.将小部件apk同步并安装到您的模拟器/设备上后,将您的eclipse工作区切换到DDMS模式。 You can either do this by pressing the “DDMS” labeled button on your top right corner or if you can't find it, then do it by going to “Window->Open Perspective->DDMS”. 您可以通过按右上角的“DDMS”标记按钮来执行此操作,或者如果找不到它,则可以通过转到“Window-> Open Perspective-> DDMS”来执行此操作。

3. Select the process name of your widget from the list of processes shown. 3.从显示的进程列表中选择窗口小部件的进程名称。 By default, this list appears at top left of DDMS window. 默认情况下,此列表显示在DDMS窗口的左上角。 (See screenshot below). (见下面的截图)。 If you can't see your widget's process name in the list, it is possible that the widget is not added to the home screen yet. 如果您无法在列表中看到窗口小部件的进程名称,则窗口小部件可能尚未添加到主屏幕。 So, do so. 所以,这样做。

4. Press the green debug button above the process list (See screenshot below) 4.按下进程列表上方的绿色调试按钮(参见下面的屏幕截图)

5. And that's it. 5.这就是它。 Now, if you had put a breakpoint in the code, do something that executes that piece of the code. 现在,如果您在代码中放置了断点,那么执行一些执行该代码的操作。

在此输入图像描述

I assume with "App Widget" you mean the widgets users can add to their home screens by long pressing on the background wallpaper? 我假设“App Widget”是指用户可以通过长按背景墙纸添加到主屏幕的小部件?

If your AndroidManifest.xml file is set up properly you are able to debug these widgets just like any other Android application. 如果您的AndroidManifest.xml文件设置正确,您就可以像调试任何其他Android应用程序一样调试这些小部件。

However, note that you need to add your widget to the home screen first. 但请注意,您需要先将小部件添加到主屏幕。

Once you've done that, you should see your widget process being listed under the DDMS mode perspective in Eclipse. 完成后,您应该会在Eclipse中的DDMS模式透视图下看到您的窗口小部件进程。 You can attach the debugger and debug your code. 您可以附加调试器并调试代码。

Android Studio Android Studio

It is really simple. 这很简单。 Just set up your debug points within your class that extends AppWidgetProvider . 只需在您的类中设置extends AppWidgetProvider调试点。

From here... 从这里...

  1. Start up your emulator OR Hook up your phone via USB cable 启动模拟器通过USB线连接手机
  2. Select the Debug icon like normally. 像往常一样选择Debug图标。
  3. Wait for your app to start 等待您的应用开始
  4. Go to your home screen 转到主屏幕
  5. Add your Widget OR go to the screen with your Widget already on it 添加您的窗口小部件转到屏幕,其中已经有您的窗口小部件

From this point, if you have a breakpoint within the onUpdate(...) method, then your debugging of the widget will start 从这一点来看,如果你在onUpdate(...)方法中有一个断点,那么你的小部件调试就会开始

Eclipse 日食

StarsSky 's answer StarsSky的回答

Android Studio Android Studio

I did not find a "structured" way to explicitly debug an App Widget. 我没有找到一种“结构化”的方式来显式调试App Widget。

My workaround: 我的解决方法:

Make sure you have an Activity in your project - usually you will have at least a Setting Activity, but if not, just make a dummy Activity that doesn't have to do anything. 确保你的项目中有一个Activity - 通常你至少会有一个Setting活动,但如果没有,只需做一个不需要做任何事情的虚拟Activity。

In your Manifest, add this Activity and mark it as the launching activity: 在您的清单中,添加此活动并将其标记为启动活动:

<activity android:name=".activity.SettingActivity"
    android:label="@string/setting_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>

now you should place your breakpoint wherever you like to debug, and launch your application using the 现在你应该把你的断点放在你想调试的地方,然后用你的应用程序启动你的应用程序 在此输入图像描述 button. 按钮。 Now the code of the whole application is under the debug session and the debugger will stop at any breakpoint, including the widget. 现在整个应用程序的代码都在调试会话下,调试器将在任何断点处停止,包括小部件。

Note: before production, remove the launching intent filter from your manifest, if you don't mean for this Activity to be launched directly from the device launchpad 注意:在生产之前,如果您不是要直接从设备启动板启动此活动,请从清单中删除启动意图过滤器

        <activity android:name=".activity.**SettingActivity**"
        android:label="@string/setting_name">
        <!--<intent-filter>-->
            <!--<action android:name="android.intent.action.MAIN"/>-->
            <!--<category android:name="android.intent.category.LAUNCHER"/>-->
        <!--</intent-filter>-->
    </activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM