0

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.?

RajSharma
  • 1,941
  • 3
  • 21
  • 34
mahesh
  • 147
  • 12

1 Answers1

0

You can check if screen is off or on via BroadcastReceiver, check below link you will find it useful for you.

Android Screen Timeout

Community
  • 1
  • 1
  • This is not help full,because i am start activity from broadcast receiver. there is no destroy method to destroy screen_time_out varable value. – mahesh Jun 27 '15 at 13:53
  • @peter i am trying to start activity when scree_off and it's work, when i start activity with delay with above code, activity start on any time when i use other app. if screen off one time then, sure activity start after some seconds. but i want to stop that activity to start if user action is present. – mahesh Jun 27 '15 at 14:00