zoukankan      html  css  js  c++  java
  • 防止APP退到被安卓系统清理

    一个是尽量提高APP权限,无非就是保持APP始终界面在前台

    二是使用守护进程方法,被清理了立刻自己启动,

    三是前台跟后台进程分开,被重启了恢复原始环境。

    // 申请设备电源锁,在服务start的时候。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    private WakeLock mWakeLock;
     
    private void acquireWakeLock()
    {
        if (null == mWakeLock)
        {
            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "LoginService");
            if (null != mWakeLock) {
                mWakeLock.acquire();
            }
        }
    }
     
    // 释放设备电源锁,在服务Destory的时候
    private void releaseWakeLock()
    {
        if (null != mWakeLock)
        {
            mWakeLock.release();
            mWakeLock = null;
        }
    }

    这个方法是防止手机休眠。你的服务就会一直运行下去,不会被系统kill掉。亲测可行。
    还有在onStartCommand里面最后return super.onStartCommand(intent, START_STICKY, startId);

    QQ在通知栏不是设了一个不同于一般通知的通知

    代码如下:

    1
    2
    3
    4
    Notification notification = new Notification(R.drawable.qqbatch_logo, getString(R.string.app_name),System.currentTimeMillis());
            PendingIntent pendingintent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
            notification.setLatestEventInfo(this, "xxxx""xxxxxxxxx", pendingintent);
            startForeground(0x111, notification);
  • 相关阅读:
    springboot 集成redission 以及分布式锁的使用
    springboot 使用线程池
    springboot 引入logback框架
    StringRedisTemplate 使用示例,工具类
    XHR post请求下载文件
    java List对象排序
    springboot中使用resttemplate调用服务是设置header中的accept-charset
    面试
    本地包打到项目中利用maven
    sql
  • 原文地址:https://www.cnblogs.com/lucktian/p/6952840.html
Copyright © 2011-2022 走看看