0

I am developing an app, where i want the screen to be unlocked as long as my app is running. This is what i have tried,

    @Override
protected void onResume() 
{

    Log.e("inside","main onre");

    //for avoiding screen locking
    Window wind;
    // TODO Auto-generated method stub
    super.onResume();
    wind = this.getWindow();
    wind.addFlags(android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    wind.addFlags(android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    wind.addFlags(android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}

Evrything works fine, but the problem is when i move from one activity to another activity, the lock screen comes to the foreground for a fraction of a second and goes background again, which makes the transition look ugly. How can i avoid this?

Let me know, thanks!

Dave
  • 297
  • 3
  • 4
  • 15

1 Answers1

0

Try this onCreate

getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Amsheer
  • 7,046
  • 8
  • 47
  • 81
  • its working fine for version greater than 2.3.5 , but the not for versions below 2.3.5 .. so i am using the following code for version below 2.3.5,KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock keyguard = km.newKeyguardLock("MyApp"); keyguard.disableKeyguard(); – Dave Jun 18 '13 at 10:14