This article analyzes the precautions for Android Service self-start. Share it for your reference, as follows:
@Override public void onStart(Intent intent, int startId) { (intent, startId); if(intent == null) return; } @Override public void onDestroy() { (); Intent intent = new Intent(, ); startService(intent); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // flags = Service.START_STICKY; flags = Service.START_REDELIVER_INTENT; return (intent, flags, startId); }
PS:The key point is this flags . At the beginning, use Service.START_STICKY; Service often automatically checks for a long time before finding that the intent in onStart is null when it is started again, and change it to flags = Service.START_REDELIVER_INTENT;
For more information about Android related content, please check out the topic of this site:Android debugging skills and solutions to common problems》、《Android development introduction and advanced tutorial》、《Android multimedia operation skills summary (audio, video, recording, etc.)》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.