调试主屏幕小部件时在AndroidStudio中如何断开调试器?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (6)
  • 关注 (0)
  • 查看 (239)

我正在尝试调试我制作的Android主屏幕小部件应用程序。当按下小部件上的按钮时,调试器就会启动,然后它就会断开与VM的连接。没有说明理由。我正在使用Windows 10。

日志上是这样写的:

D/Atlas: Validating map... D/libEGL: loaded
/system/lib/egl/libEGL_emulation.so D/libEGL: loaded
/system/lib/egl/libGLESv1_CM_emulation.so D/libEGL: loaded
/system/lib/egl/libGLESv2_emulation.so

D/         ] HostConnection::get() New Host Connection established 0xef0394f0, tid 3709 
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Enabling debug mode 0 W/EGL_emulation: eglSurfaceAttrib not implemented 
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xef1485e0, error=EGL_SUCCESS
D/roboguice.RoboGuice: Using annotation database(s).
D/roboguice.RoboGuice: Using annotation database(s) : [, roboguice]
D/roboguice.RoboGuice: Time spent loading annotation databases : 21
W/art: Verification of com.gdbd.geedeebeedee.model.GdbdWidgetRecord 
    com.gdbd.geedeebeedee.model.GdbdWidgetRecordsRealmImpl.create(java.util.Date) took 127.878ms
W/art: Verification of com.gdbd.geedeebeedee.model.GdbdWidgetRecord
    com.gdbd.geedeebeedee.model.GdbdWidgetRecordsRealmImpl.getTodaysRecord() took 111.586ms
D/GdbdWidgetBase: Received intent: android.appwidget.action.APPWIDGET_ENABLED
D/GdbdWidgetBase: Updating widget index: 0 with id: 23
D/GdbdWidgetBase: Received intent: android.appwidget.action.APPWIDGET_UPDATE
D/GdbdWidgetBase: Received intent: android.appwidget.action.APPWIDGET_UPDATE_OPTIONS
D/GdbdWidgetBase: Received intent: change_day_staus
I/art: Thread[5,tid=3470,WaitingInMainSignalCatcherLoop,Thread*=0xf3c30c00,
    peer=0x22c0a0a0,"Signal Catcher"]: reacting to signal 3
I/art: Wrote stack traces to '/data/anr/traces.txt' 
Disconnected from the target VM, address: 'localhost:8619', transport: 'socket'

模拟器是GoogleNexus55.1.0API 22。

这些是Gradle构建设置:

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.gdbd.geedeebeedee"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    } }

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile group: 'com.google.code.gson', name: 'gson', version: '2.3.1'
    compile 'com.android.support:appcompat-v7:25.0.0'

    compile 'org.roboguice:roboguice:3.+'
    provided 'org.roboguice:roboblender:3.+'

    testCompile 'junit:junit:4.12' }

有人知道发生了什么事吗?

很明显这个过程已经结束了。

D/OpenGLRenderer: Enabling debug mode 0 
W/EGL_emulation: eglSurfaceAttrib not implemented 
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xf3ff6900, error=EGL_SUCCESS
D/roboguice.RoboGuice: Using annotation database(s).
D/roboguice.RoboGuice: Using annotation database(s) : [, roboguice]
D/roboguice.RoboGuice: Time spent loading annotation databases : 19
80:   80 D/         ] Socket deconnection 
D/GdbdWidgetBase: Received intent: change_day_staus
80:   80 D/         ] Socket deconnection
80:   80 D/         ] Socket deconnection
80:   80 D/         ] Socket deconnection
80:   80 D/         ] Socket deconnection 
I/art: Thread[5,tid=13474,WaitingInMainSignalCatcherLoop,Thread*=0xf3c30c00,
    peer=0x12c0a0a0,"Signal Catcher"]: reacting to signal 3
I/art: Wrote stack traces to '/data/anr/traces.txt'

添加Androidmanifest文件

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="roboguice.modules"
        android:value="com.gdbd.geedeebeedee.model.ModelModule" />


    <activity
        android:name=".activity.StatsActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver android:name=".widget.GdbdWidgetBase" >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <intent-filter>
            <action android:name="change_day_staus" />
        </intent-filter>


        <meta-data android:name="android.appwidget.provider"
            android:resource="@xml/gdbd_widget_info" />

    </receiver>

</application>

编辑3traces.txthttps://ufile.io/c41eb

编辑4GdbdWidgetBase

@Inject
    GdbdWidgetRecords gdbdWidgetRecords;

    public void onHandleUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        // Perform this loop procedure for each App Widget that belongs to this provider
        for (int widgetIndex = 0; widgetIndex < appWidgetIds.length; widgetIndex++) {
            int widgetId = appWidgetIds[widgetIndex];
            Log.d(TAG, "Updating widget index: " + widgetIndex + " with id: " + widgetId);

            GdbdWidgetRecord todaysRecord = gdbdWidgetRecords.getTodaysRecord();

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.gdbd_widget);

            if(todaysRecord.getCurrentStatus() == DayStatus.GOODDAY)
                views.setImageViewResource(R.id.btnClicker, R.drawable.ic_gd);
            else if(todaysRecord.getCurrentStatus() == DayStatus.BADDAY)
                views.setImageViewResource(R.id.btnClicker, R.drawable.ic_bd);
            else if(todaysRecord.getCurrentStatus() == DayStatus.NOTSET)
                views.setImageViewResource(R.id.btnClicker, R.drawable.ic_undecided);


            Intent intent = new Intent(context, GdbdWidgetBase.class);
            intent.setAction(CHANGE_DAY_STATUS);
            intent.putExtra(WIDGET_ID_EXTRA, widgetId);
            PendingIntent changeStatusIntent = PendingIntent.getBroadcast(context, widgetId, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            views.setOnClickPendingIntent(R.id.btnClicker, changeStatusIntent);

            scheduleUpdateAtMidnight(context, widgetId);

            appWidgetManager.updateAppWidget(widgetId, views);
        }
    }

    @Override
    public void onHandleReceived(Context context, Intent intent) {
        Log.d(TAG, "Received intent: " + intent.getAction());
        //Log.d(TAG,"getDebugUnregister: " + (getDebugUnregister()?"true":"false"));

        if (CHANGE_DAY_STATUS.equals(intent.getAction())) {

            int appWidgetId = intent.getIntExtra(WIDGET_ID_EXTRA, -1);
            if (appWidgetId >= 0) {
                GdbdWidgetRecord todaysRecord = gdbdWidgetRecords.getTodaysRecord();
                Log.d(TAG, "today record: " + todaysRecord.toString());
                DayStatus newDayStatus = DayStatus.NOTSET;

                if(todaysRecord.getCurrentStatus() == DayStatus.NOTSET)
                    newDayStatus = DayStatus.GOODDAY;
                else if(todaysRecord.getCurrentStatus() == DayStatus.GOODDAY)
                    newDayStatus = DayStatus.BADDAY;
                else if(todaysRecord.getCurrentStatus() == DayStatus.GOODDAY)
                    newDayStatus = DayStatus.NOTSET;

                Log.d(TAG, "newDayStatus: " + newDayStatus);

                gdbdWidgetRecords.changeTodaysStatus(newDayStatus);
                onHandleUpdate(context, AppWidgetManager.getInstance(context), new int[]{appWidgetId});
            }
        }
    }

    private void scheduleUpdateAtMidnight(Context context, int widgetId) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.SECOND, 1);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.add(Calendar.DAY_OF_YEAR, 1);

        Intent updateAtMidnightIntent = new Intent(context, GdbdWidgetBase.class);
        updateAtMidnightIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        updateAtMidnightIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{widgetId});

        PendingIntent broadcastIntent = PendingIntent.getBroadcast(context, widgetId + 1,
                updateAtMidnightIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), broadcastIntent);
        } else {
            alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), broadcastIntent);
        }
    }

断点

01-09 22:28:20.861 3881-3881/com.gdbd.geedeebeedee D/GdbdWidget: Received intent: android.appwidget.action.APPWIDGET_ENABLED
01-09 22:29:20.854 3881-3886/com.gdbd.geedeebeedee I/art: Thread[2,tid=3886,WaitingInMainSignalCatcherLoop,Thread*=0x7fbcebe06000,peer=0x2ac070a0,"Signal Catcher"]: reacting to signal 3
01-09 22:29:21.013 3881-3886/com.gdbd.geedeebeedee I/art: Wrote stack traces to '/data/anr/traces.txt'

然而,对于我自己在小部件内按下按钮时发送的内容,则需要10秒。

01-09 22:34:25.353 4314-4314/com.gdbd.geedeebeedee D/GdbdWidget: Received intent: change_day_staus
01-09 22:34:35.362 4314-4319/com.gdbd.geedeebeedee I/art: Thread[2,tid=4319,WaitingInMainSignalCatcherLoop,Thread*=0x7fbcebe06000,peer=0x2ac070a0,"Signal Catcher"]: reacting to signal 3
01-09 22:34:35.549 4314-4319/com.gdbd.geedeebeedee I/art: Wrote stack traces to '/data/anr/traces.txt'
提问于
用户回答回答于

热门问答

腾讯云 COS 怎么才能外链调用 m3u8 到别的网站播放?

滑稽园扛把子

Swoole · PHP开发工程师 (已认证)

As a PHP Developer
推荐
设置公有读私有写:当访问对象时,COS 读取到对象的权限为公有读,此时无论存储桶为何种权限,对象都可以被直接下载 设置步骤 登录 对象存储控制台,选择左侧菜单栏【存储桶列表】,进入存储桶列表页面。单击需要修改对象权限的对应存储桶,进入存储桶。 📷 找到需要设置权限的对象(如 e...... 展开详请

Ubuntu搭建的WordPress如何修改php.ini?

滑稽园扛把子

Swoole · PHP开发工程师 (已认证)

As a PHP Developer
推荐
php新手很多不知道怎么查配置文件在哪,这里提供一个很简单的方法 使用 php -i 命令可以打印php的详细信息,可以把这堆东西输出一下 php -i > outputphp.txt,结合 grep 查找命令 php -i| grep php.ini 打印结果如下 Config...... 展开详请

归档存储采用的存储介质是什么, 安全可靠吗?

滑稽园扛把子

Swoole · PHP开发工程师 (已认证)

As a PHP Developer
推荐
归档存储主要是针对海量、重要且访问频率极低的非结构化数据进行长期的归档保存和备份管理。 在数据安全层面,归档存储提供数据锁定机制,防止数据被修改和删除,保障数据安全。 技术架构: image.png 与对象存储的差异 归档存储 CAS 是一项离线存储服务,不同于在线的对象存储 ...... 展开详请

在按官网手册排错后依然提示1004错误?

看你的代码好像是短信相关的代码,1004错误代表请求包解析失败,通常情况下是由于没有遵守 API 接口说明规范导致的。 建议您通过以下方式定位解决: 首先,要确认发送的请求是否是标准的 json 格式; 第二,检查是否有将单引号当做双引号使用(json 标准应该是双引号); 第...... 展开详请

redis数据库应该怎样连接???

滑稽园扛把子

Swoole · PHP开发工程师 (已认证)

As a PHP Developer
推荐
实例初始化完成后,连接腾讯云Redis时,需要输入设置的密码。主从版和集群版的连接示例如下 主从版连接示例 主从版支持2种格式 • 格式1,“实例id:密码”的格式类型,例如您的实例id是crs-bkuza6i3,设置的密码是abcd1234,则连接命令如下 redis-cli ...... 展开详请

如何使用holer实现从外网访问本地WEB应用?

Dingda

Dingda · 站长 (已认证)

多一些不为什么的坚持
推荐
解压holer软件 获取holer access key信息: 在holer官网上申请专属的holer access key或者使用开源社区上公开的access key信息。 启动holer服务: Windows系统平台: 打开CMD窗口进入可执行程序所在的目录下,执行命令:...... 展开详请

所属标签

扫码关注云+社区