Possible Duplicate:
Lock the Android device programmatically
Does the application have the ability to lock the screen? I have tried the following code, but nothing happens.
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.reenableKeyguard();
Your code looks fine and it should work..
Have you included the required permission in android manifest file.
And for further reference, If you want the source code for screen lock implementation, then please check this question posted in stackoverflow and a link from android developer site.
Source of Android's lock screen
http://developer.android.com/guide/topics/admin/device-admin.html
http://developer.android.com/reference/android/app/KeyguardManager.KeyguardLock.html