Screen Lock from receiver
<p>I am trying to Lock and unlock the screen,</p>

<p>The thing I am doing it as the following 
 A <code>Broadcast receiver</code> which checking whether the screen is ON of OFF,If the Screen is ON it will Lock the screen and if OFF it will unlock the screen.</p>

<p>The code I am using in the <code>Broadcast receiver</code> is</p>

<pre><code>public void onReceive(Context context, Intent intent) {

        System.out.println("Entered Broadcaste Reciever........");
       context1 = context;
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            // DO WHATEVER YOU NEED TO DO HERE
             mShaker = new ShakeListener(context);
                mShaker.setOnShakeListener(new ShakeListener.OnShakeListener () {
                  public void onShake()
                  {
                     PowerManager TempPowerManager = (PowerManager) context1.getSystemService(Context.POWER_SERVICE);
                    PowerManager.WakeLock TempWakeLock = TempPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE, "TempWakeLock");
                    TempWakeLock.acquire();
                    final Vibrator vibe = (Vibrator)context1.getSystemService(Context.VIBRATOR_SERVICE);
                    vibe.vibrate(100);
            System.out.println("LISTENING SHAKE");
                  }
                });

        }
        else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            // AND DO WHATEVER YOU NEED TO DO HERE

             mShaker = new ShakeListener(context);
                mShaker.setOnShakeListener(new ShakeListener.OnShakeListener () {
                  public void onShake()
                  {

                        mDPM = (DevicePolicyManager)context1.getSystemService(Context.DEVICE_POLICY_SERVICE);



                    ComponentName mAdminName = new ComponentName(context1,LockActivity.class);
                    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); 
                    filter.addAction(Intent.ACTION_SCREEN_OFF);
                    BroadcastReceiver mReceiver = new ScreenReceiver();
                    context1.registerReceiver(mReceiver, filter);
                    System.out.println("The Device  device admin enabled");
                    Intent  intent = new             Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
  intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
                                           intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"onEnabled");
                                   mDPM.lockNow();
                                   mDPM.setMaximumTimeToLock(mAdminName,0);
                                   intent.putExtra("force-locked", DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
   //                                           startActivityForResult(intent, 1); 
                  }
                });
        }
</code></pre>

<p>The problem is it is starting properly and upto 5 shakes its working properly and after that it is going infinite state and device get stucked..Somebody help me to find the solution</p>
