在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:AndroidAPP保活开源软件地址:https://gitee.com/jiangjiesheng/androidapp_preservation开源软件介绍:KeepAppAlive安卓App保活依赖库 使用方法
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' }
public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); KeepAliveManager.initWithApplicationContext(this.getApplicationContext(),false);//最好放在application中初始化 } }
首先获取实例 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(); } 补充说明
|
请发表评论