0

I have code below that I have inserted into my onCreate method, but it dosent seem to work. I want it to launch other activity when screen goes off/battery button press.

CODE:

protected void onStartCommand() {
    // TODO Auto-generated method stub
    super.onStart();
    ScreenReceiver();
}

 public class ScreenReceiver extends BroadcastReceiver {

      @Override
        public void onReceive(Context context, Intent intent) {

            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {

                lock.reenableKeyguard();        
                Intent s = new Intent(Activity1.this , Activity2.class); 
                startActivity(s);


            } 
            else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                lock.disableKeyguard(); 



            }
        }
    }

Any help would be VERY appreciated?

David
  • 99
  • 1
  • 9

1 Answers1

0

You need to acquire a WakeLock before you try starting that Activity.

Refer to CommonsWare answer here android AlarmManager not waking phone up

Community
  • 1
  • 1
Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34