I recommend you to use two activities.
Add a timer to the second activity that ticks every second (1000ms) and increments a global counter variable. If it reaches 30 then close the activity.
Reset the counter in any of the user related events.
Make sure to declare the timer as a process global variable. Enable it in Activity_Resume and disable in Activity_Pause.