package com.arpa.hndahesudintocctmsdriver.service; import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.util.Log; import androidx.annotation.Nullable; import com.arpa.hndahesudintocctmsdriver.ui.MainActivity; /** * @author hlh * @version 1.0.0 * @date 2021/8/31 19:54 * @description: */ public class RestartService extends Service { private Context con; @Nullable @Override public IBinder onBind(Intent intent) { return null; } //Service被启动的时候回调onStartCommand方法 public int onStartCommand(Intent intent, int flags, int startId){ Log.e("---static---","启动"); return START_STICKY; } @Override public void onCreate() { super.onCreate(); con=getApplication(); Intent in=new Intent(con, MainActivity.class); startActivity(in); } @Override public void onDestroy() { super.onDestroy(); } }