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.

  • 相关阅读:
    php验证码
    php上传
    ajax的用法 资料
    ajax如何使用
    AJAX
    基础概念梳理 :
    ICompare 可比较接口
    强类型 和弱类型 c#
    .ne 基础(2)
    .net 基础(一)
  • 原文地址:https://www.cnblogs.com/zhuqiang/p/2936956.html
Copyright © 2011-2022 走看看