代码拉取完成,页面将自动刷新
安卓App保活依赖库
1、gradle引入依赖
Step 1. Add the JitPack repository to your build file Add 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();
}
补充说明
作者:江节胜
微信:767000122 (欢迎添加好友)
Q Q :596957738
联系邮箱:dev@jiangjiesheng.cn
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型