Invoke service when screen turns on (Android) <p>I am creating a lockscreen app with facial recognition. As a first step I am creating a simple lockscreen that unlocks on <code>Button</code> click. The lockscreen should start when <code>Switch</code> on <code>MainActivity</code> is turned on. I created a <code>Service</code> which starts my lockscreen activity, but the activity does not show again once I turn off and then turn on my screen. I am a beginner in android and don't understand what to do. I would be happy if i could get some help.</p> <p>The java files are:</p> <p>MainActivity.java</p> <pre><code>package com.sanket.droidlockersimple; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.widget.CompoundButton; import android.widget.Switch; public class MainActivity extends ActionBarActivity { private Switch enableLocker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); enableLocker = (Switch) findViewById(R.id.enableLocker); enableLocker.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(enableLocker.isChecked()) { Intent intent = new Intent(MainActivity.this, DroidLockerService.class); startService(intent); } } }); } } </code></pre> <p>DroidLockerService.java</p> <pre><code>package com.sanket.droidlockersimple; import android.app.Service; import android.content.Intent; import android.os.IBinder; public class DroidLockerService extends Service { @Override public IBinder onBind(Intent intent) { return null; } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Intent intent1 = new Intent(this, LockScreen.class); intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent1); } @Override public void onDestroy() { super.onDestroy(); } } </code></pre> <p>LockScreen.java</p> <pre><code>package com.sanket.droidlockersimple; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.view.WindowManager; import android.widget.Button; public class LockScreen extends ActionBarActivity { private Button unlock; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); setContentView(R.layout.activity_lock_screen); Button unlock = (Button) findViewById(R.id.button); unlock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } } </code></pre>