1

To close the current activity and start another activity if the user does not do any work on the present screen. Say I am at Activity1 and I am not doing any work for 30 seconds. I want that another activity say Activity2 starts automatically and Activity1 finishes.

sneaker_android
  • 380
  • 3
  • 8

2 Answers2

0

You can create a variable and store the system time in it when Activity1 starts.

Refer this link for current System time: Get current time and date on Android

Then you can create a loop and check whether the variable's value is less than 30 sec from the System's current time. If yes you can call a method.

In the method you can start the new activity (Activity2).

//To start new activity

Intent intent=new Intent(your_current_class.this,activity_you_want_to_call.class);

                                startActivity(intent);
Community
  • 1
  • 1
kittu88
  • 2,451
  • 5
  • 40
  • 80
0

You could use a Timer for this. When user go to Activity1 start that timer. In between if user does some operation, cancel old timer and start new one again for specified time. When timer time elapses, start Activity2. For reference, have a look at this answer.

Community
  • 1
  • 1
Braj
  • 2,164
  • 2
  • 26
  • 44