2

What do I want to achieve:

After 3 minutes of user inactivity I want to display a new activity.

Research:

I did look on Stackoverflow for this problem and I found some hints on how to do this using a background thread, create a base activity that register the last touch, etc.

Problem:

If I have more than, lets say 20 activities, and I don't want to extend all activities from a base Activity. This would mean that every time I create a new activity I need to extend this base one, which can create some mess if my activities already extends from some other base activities. I would like to use the class Application to handle this, so the activities would remain the same.

How can I achieve this without touching activities already created? Or do I always have to handle onUserInteraction(), or onPause(), or any other methods on Activity?

Research references:

Application idle time

Detect when application is idle in android

how to detect user inactivity in android

Community
  • 1
  • 1
Bugdr0id
  • 2,962
  • 6
  • 35
  • 59

1 Answers1

0

I'm afraid you need to collect information about open Activities somewhere (some Collection maybe). You can store this collection in Application class and write some methods for Activities to report their opening and closing. In Activity close method you can check if your collection is empty and then fire some delayed event in Handler or Timer (opening new Activity) and in Activity open method you can invalidate this delayed task.

This is very general way to achieve your goal.

Pawel Urban
  • 1,316
  • 1
  • 12
  • 28