How to make android.app.Service so that even when the phone screen is off, it works? Here is its source code:
public class S extends Service { @Override public void onStart(Intent i1, int i2) { new Timer().schedule(new TimerTask() { @Override public void run() { //..........// return; } }, 60000, 60000); } @Override public IBinder onBind(Intent i1) { return null; } } I run it like this:
public class Main extends AppCompatActivity { Intent i1; @Override protected void onCreate(Bundle i1) { super.onCreate(i1); setContentView(R.layout.layout_main); this.i1 = new Intent(this, S.class); startService(this.i1); return; } @Override protected void onDestroy() { stopService(this.i1); super.onDestroy(); return; } } The theory says: "Unlike Activity, services in Android work as background processes ... A service can continue to work until someone stops it or it stops itself." But as soon as I turn off the phone screen, the service stops working. She resumes her work only after I unlock the phone. How to fix this error?