• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

AndroidAPP保活: AndroidAPP保活,同时封装成依赖库,直接引入gradle依赖,简单几步即 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

AndroidAPP保活

开源软件地址:

https://gitee.com/jiangjiesheng/androidapp_preservation

开源软件介绍:

KeepAppAlive

安卓App保活依赖库

源码请看v1.0.0及以上分支版本

使用方法

1、gradle引入依赖

Step 1. Add the JitPack repository to your build fileAdd it in your root build.gradle at the end of repositories:

    allprojects {     repositories {      ...      maven { url 'https://jitpack.io' }      }    }

Step 2. Add the dependency

   dependencies {       implementation 'com.gitee.jiangjiesheng:androidapp_preservation:v1.0.5'   }

2、首先在Application中初始化

    public class MyApplication extends Application {        @Override        public void onCreate() {            super.onCreate();            KeepAliveManager.initWithApplicationContext(this.getApplicationContext(),false);//最好放在application中初始化        }    }

3、在需要使用的Activity页面使用:

     首先获取实例

  KeepAliveManager keepAliveManager = KeepAliveManager.getInstance(this);//获取实例

     在onCreate()中设置屏幕监听,添加受保护的Activity

    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        keepAliveManager.setKeepAliveManagerStatusListener(new KeepAliveManager.KeepAliveManagerStatusListener() {            @Override            public void onUserPresent() {                Toast.makeText(SportsActivity.this, "用户解锁了", Toast.LENGTH_LONG).show();            }        });        keepAliveManager.addRestartActivity(this.getClass()); //这里就是添加了受保护的Activity    }

     开启保活

   keepAliveManager.startKeeper();

     关闭保活

   keepAliveManager.stopKeeper();

     在onDestroy()中取消对屏幕的监听

    @Override    protected void onDestroy() {        super.onDestroy();        keepAliveManager.stopScreenListenerOnDestroy();    }

补充说明

  • 后期可以增加方法控制不同级别的保活能力,主要是了控制发热和耗电
  • 经实测,如果是在最近任务中单独选中这个运行中的app直接拖出任务栏,会导致app销魂,但是在最近任务栏点击清除所有的按钮或者在桌面点击"一键清理",一般不会被销毁。

作者:江节胜

微信:767000122 (欢迎添加好友)

Q Q :596957738

个人网站:tech.jiangjiesheng.cn

联系邮箱:[email protected]


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap