基本信息
源码名称:android 异常崩溃后 重启app(进程守护方式实现)
源码大小:21.40M
文件格式:.zip
开发语言:Java
更新时间:2019-08-01
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.sunfusheng.daemon.sample; import android.content.ComponentName; import android.content.Intent; import android.os.Looper; import android.util.Log; import com.blankj.utilcode.util.AppUtils; import com.sunfusheng.daemon.AbsHeartBeatService; /** * @author sunfusheng on 2018/8/3. */ public class HeartBeatService extends AbsHeartBeatService { private static final String TAG = "---> HeartBeatService"; private static final android.os.Handler mainThreadHandler = new android.os.Handler(Looper.getMainLooper()); @Override public void onStartService() { Log.d(TAG, "onStartService()"); } @Override public void onStopService() { Log.e(TAG, "onStopService()"); } @Override public long getDelayExecutedMillis() { return 0; } @Override public long getHeartBeatMillis() { return 30 * 1000; } @Override public void onHeartBeat() { String packetName=AppUtils.getAppPackageName(); Log.d(TAG, "onHeartBeat()" packetName); if(!AppUtils.isAppRunning(packetName)){ //方案一 AppUtils.relaunchApp(); //方案二 // Intent sayHelloIntent=new Intent(this,MainActivity.class); // sayHelloIntent.setAction(Intent.ACTION_VIEW); // sayHelloIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); // sayHelloIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); // getApplicationContext().startActivity(sayHelloIntent); // //方案三 // Intent intent = new Intent("android.intent.action.MAIN"); // intent.setComponent(new ComponentName(getApplicationContext().getPackageName(), MainActivity.class.getName())); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // getApplicationContext().startActivity(intent); Log.d(TAG, packetName " launchApp Sucess!!!!!!"); }else{ Log.d(TAG, packetName " is running"); if(!AppUtils.isAppForeground()){ Intent sayHelloIntent=new Intent(this,MainActivity.class); sayHelloIntent.setAction(Intent.ACTION_VIEW); sayHelloIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); sayHelloIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); getApplicationContext().startActivity(sayHelloIntent); Log.d(TAG, packetName " is FLAG_ACTIVITY_SINGLE_TOP!!!"); } } } }