zoukankan      html  css  js  c++  java
  • 在播放音乐的时候屏蔽back键

    Most of the time you need to create a Service to perform something in the background, and your visible Activity simply controls this Service. (I'm sure the Music player works in the same way, so the example in the docs seems a bit misleading.) If that's the case, then your Activity can finish as usual and the Service will still be running.

    A simpler approach is to capture the Back button press and call moveTaskToBack(true) as follows:

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            moveTaskToBack(true);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    I think the preferred option should be for an Activity to finish normally and be able to recreate itself e.g. reading the current state from a Service if needed. But moveTaskToBack can be used as a quick alternative on occasion.

  • 相关阅读:
    RPA-UiPath视频教程2
    skywalking链路监控
    RPA-UiPath视频教程1
    Redis基础与性能调优
    tomcat调优
    DDos、CC攻击与防御
    UiPath官方视频Level2
    UiPath直播课程
    UiPath手把手教程
    【0】python核心编程,第二章
  • 原文地址:https://www.cnblogs.com/zhuqiang/p/2936956.html
Copyright © 2011-2022 走看看