1

I am stuck and working on android app, i want when i close my application,then if user do not touch screen for x time, for example for 1minute user do not touch the screen or use the device then my application start automatically after x time..how i can achieve this please help..Thanks

Farhan Shah
  • 2,344
  • 7
  • 28
  • 54
  • can u pls share how u achieve this task ? – Erum May 06 '15 at 06:14
  • @Erum the question is one year old,and i forgot the module and today and yesterday i am busy to achieve my deadlines,i will check this module on weekend and will let u know. – Farhan Shah May 07 '15 at 06:03

1 Answers1

4

You could make use of service. As soon as your application is exited you could start a timer or counter. If there are no interactions on phone by the user you could start your activity from ur service (or) You could implement ur service in such a way that when the phone is going into sleep mode(which means there was no interaction by the user on the phone) you can start your activity.

UPDATED

    protected CountDownTimer timer = new CountDownTimer(5000, 5000){
        @Override
        public void onTick(long millisUntilFinished) {
             Log.d("onTick", "Entered");
        }

        @Override
        public void onFinish() {
             Log.d("onFinish", "Entered");
        }
    };
ik024
  • 3,566
  • 7
  • 38
  • 61
  • thanks alot for ur reply..through services i have done the when phone is going to sleep then after 3minutes my app start automatically and work's fine..but now my problem is when i close my application,and if user do not interaction or use the phone then my application start automatically after x time duration..can u got my point? – Farhan Shah Mar 04 '14 at 05:52
  • can u please tell me that how i can start timer if ther is no interaction by the user...if user is intercation then how to reset timer? – Farhan Shah Mar 04 '14 at 06:00
  • I am not quite sure but u can refer this question http://stackoverflow.com/questions/11782501/how-to-detect-user-interaction-of-any-kind – ik024 Mar 04 '14 at 06:51
  • make use of CountDownTimer class to start and stop the timer – ik024 Mar 04 '14 at 06:53
  • bro can u give example of starting sountdwon timer?please – Farhan Shah Mar 04 '14 at 07:01
  • 1
    I have ediited my ans. To start the timer call timer.start() and to stop timer.stop(). This particular timer is for 5s (5000 ms) – ik024 Mar 04 '14 at 07:57