aoi学院

Aisaka's Blog, School of Aoi, Aisaka University

开启服务和绑定服务的区别/优缺点

开启服务:startService() → stopService()(其生命周期为onCreate() → onStartCommand() → onDestroy())

绑定服务:bindService() → unBindService()(其生命周期为onCreate() → onBind() → onUnbind() → onDestroy())

区别:startService()可以长期在后台运行,bindService()不可以在后台长期运行;bindService()启动服务可以跟服务进行通讯,startService()启动服务不可以跟服务进行通讯。

解决方法:混合两种启动方式,先startService()再bindService(),这样又可以长期运行又可以跟服务进行通讯。


阅读全文 »

Broadcast动态注册与静态注册

  1. 动态注册

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    // 在onCreate()中注册registerBatteryReceiver();

    private void registerBatteryReceiver() {
    // 收听的频道是 电量变化
    IntentFilter intentFilter = new IntentFilter();
    // 设置频道
    intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    // 创建一个广播接收者
    mBatteryLevelReceiver = new BatteryLevelReceiver();
    // 注册
    this.registerReceiver(mBatteryLevelReceiver, intentFilter);
    }

    /**
    * 创建一个广播接收者
    */
    private class BatteryLevelReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
    Log.d(TAG, "Battery change action is == " + action);
    int currentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
    Log.d(TAG, "当前电量:" + currentLevel);
    if (mBatteryLevelText != null) {
    mBatteryLevelText.setText("当前电量:" + currentLevel);
    }
    int maxLevel = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
    float percent = currentLevel * 1.0f / maxLevel * 100;
    Log.d(TAG, "当前电量百分比为:" + percent + "%");
    }
    }
    }

    // 在onDestroy()中取消广播注册

    @Override
    protected void onDestroy() {
    super.onDestroy();
    // 取消广播注册
    if (mBatteryLevelReceiver != null) {
    this.unregisterReceiver(mBatteryLevelReceiver);
    }
    }
阅读全文 »

Activity启动模式

  1. <activity android:name=”.FirstActivity” android:launchMode=”standard”>

    standard模式会创建新的任务,并把新Activity置于当前栈顶,点击返回键相当于移除栈顶Activity,栈空时销毁Task。

    使用场景:默认的启动模式,大多数场景都是用该模式。

  2. <activity android:name=”.FirstActivity” android:launchMode=”singleTop”>

    singleTop模式在standard模式的基础上,表示如果当前栈顶为该Activity,则不会创建新的Activity(防止栈顶Activity重复创建)。

    使用场景:一般来说,为保证只有一个任务,而不被创建多个时需要此模式。例如,浏览器的书签被动调用的界面)、应用的推送通知、配置及配置里的内容等。

阅读全文 »

本篇学习报告基于2020 KDD(Knowledge Discovery and Data Mining, CCF A类会议)的论文:《LayoutLM: Pre-training of Text and Layout for Document Image Understanding》,该论文由微软自然语言计算组提出。

阅读全文 »

本篇学习报告的内容为“SeqSleepNet:用于序列到序列自动睡眠分期的端到端分层循环神经网络”,所参考论文为《SeqSleepNet: End-to-End Hierarchical Recurrent Neural Network for Sequence-to-Sequence Automatic Sleep Staging》。本论文将任务作为序列到序列的分类问题,接收多个时期的序列作为输入,并立即对其所有标签进行分类。该网络在MASS数据集上进行测试,睡眠阶段五分类准确度为87.1%。相关成果在2019年发表于《IEEE TRANSACTIONS ON NEURAL SYSTEMS AND REHABILITATION ENGINEERING》,原文链接与代码地址见文末。

阅读全文 »