package com.emato.ich.crash;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.emato.ich.MainActivity;
import com.emato.ich.utils.Log;

/**
 * 系统启动广播接收器
 */
public class BootBroadcastReceiver extends BroadcastReceiver {
    static final String ACTION = "android.intent.action.BOOT_COMPLETED";
    private static final String TAG = BootBroadcastReceiver.class.getName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION)) {
            try {
                // 开机启动的Activity
                Intent activityIntent = new Intent(context, MainActivity.class);
                activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                // 启动Activity
                context.startActivity(activityIntent);
                //2.如果自启动Activity
                context.startActivity(activityIntent);
                Log.i(TAG, "=========================>应用断点重启完成! ");
                //3.如果自启动服务
//            context.startService(intent);
            } catch (Exception e) {
                Log.e(TAG, "=========================>应用断点重启失败! ", e);
            }
        }
    }
}