Here is a code of Activity that will automatically close itself after five seconds.
public class TestActivity extends ActionBarActivity {
private static final int DELAY = 5000;
public boolean inactive;
Handler mHideHandler = new Handler();
Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
if(inactive) {
finish();
} else {
mHideHandler.postDelayed(mHideRunnable, DELAY);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_annotation_test);
mHideHandler.postDelayed(mHideRunnable, DELAY);
}
}
Now all you need to do is to change inactive variable to true after user interaction. Which will cancel activity finish and start new countdown.
0
solved Close activity after x minutes of inactive