Show Action Bar When User Does Not Interact For Some Time In Android
Solution 1:
ultimately you have to track the user interactions. have a look at this post : tracking-user-idle-time-within-the-app-in-android
By using this concept you can track the time and save in preference.
Now remaining logic is only for showing the actionbar if user is not active for some time interval (suppose 2seconds).
For that, You can create a Thread
inside your Activity
which periodically (in your case,at every 2seconds) checks last user-interaction time by calling getElapsed()
method.if getElapsed()
is greater than your desired time(2seconds).then show actionbar using getActionBar().show()
method.
Solution 2:
You're probably looking for a FullScreenActivity behaviour, like the one provided on the FullScreenActivity template. Read more about it: http://developer.android.com/tools/projects/templates.html#full-screen-activity
With this, you will have for free, a well tested code, with the behaviour: auto hiding the actionbar and showing it back when there's interaction.
Solution 3:
You could set up an AsyncTask, put a sleep in there before showing the ActionBar, and if the user touches anything else cancel the task. See here for canceling task. I'd put the isCancelled() check after the sleep and before showing the ActionBar
EDIT: What I'd do for your problem is
protectedStringdoInBackground(String... params) {
// TODO Auto-generated method stubSystemClock.sleep(3000);
if (!isCancelled()) {
runOnUiThread(newRunnable() {
@Overridepublicvoidrun() {
//Show the actionbar code here
}
});
}
returnnull;
}
Post a Comment for "Show Action Bar When User Does Not Interact For Some Time In Android"