The current demand is. Monitor the plugging and unplugging of headphones after turning on the phone or without opening the app. to perform different operations.
The current thinking is.
Start a service after booting, and monitor the headphone plugging and unplugging status in the service. If headphones are plugged in, open an Activity. Otherwise close the current Activity.
Is there something wrong with the whole idea??
The problem is how the service process survives
import android.app.ActivityManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
import java.util.List;
public class HeadPhoneService extends Service {
}