I am developing lock app. I am trying to start activity after screen time out. but It is not working, because i don't know how to check screen is time out or not.
i am using this code to set screen-time-out time android.provider.Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT, time);
. I can check screen-time-out value is null or not using this code if(android.provider.Settings.System.SCREEN_OFF_TIMEOUT != null)
.
I have tried this code but it is not working perfectly. I have also tried below code but it is working for fixed time.
`if (intent.getAction().equals("android.intent.action.SCREEN_OFF"))
{ delay = 5000;
v = sharedpreferences.getInt("lock1", 0);
if(android.provider.Settings.System.SCREEN_OFF_TIMEOUT != null){
if(v == 1)
{
final Intent localIntent2 = new Intent(context, shake_or_swipe.class);
localIntent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
localIntent2.putExtra("pin_password", s1);
new Intent("android.intent.action.MAIN");
//.addCategory("android.intent.category.HOME");
/* handler = new Handler();
delayRunnable = new Runnable() {
@Override
public void run() {
context.startActivity(localIntent2);
}
};
handler.postDelayed(delayRunnable, delay);
*/
}
}`
this code is working for specific time like 5 seconds. when the screen is on above activity should not start. but when screen goes off again this activity should start after every five minutes.
any one can tell me how can i start activity after screen_time_out
with delay of some second.?