tags:

views:

34

answers:

1

I have a repeating alarm setting, I have the activity being launched, the piece I'm missing is having this triggered after x minutes of inactivity.

I'm considering keying off of SCREEN_OFF in a service and then setting an alarm and canceling it on SCREEN_ON, does anyone have an intent or other suggestion for this. I've considering polling for tasks, all kinds of pieces but I'm stuck.

Requirement: - App launches, alarm is set to relaunch app after 5 minutes, user exits/app exits after one minute - alarm triggers, detects phone is in use, resets alarm to trigger in fives minutes - if phone is idle relaunches app for one minute

A: 

Your question is ambiguous: "set to relaunch intent". Do you mean set to relaunch the activity with an intent or set to send an intent? What is the intent intended to accomplish?

If you wish to monitor screen on and off you simply need to register a broadcastreceiver in the manifest for the screen_off and screen_on intent, and run code depending on the intent that fired it: set a 5 minute delayed alarm on screen_off that is cancelled by the screen_on event.

Without knowing the purpose of the intent or why inactivity (assuming here you mean user inactivity as in screen_off/ cpu sleep) it's really hard to answer.

Android Dev Dude
You're right I just re-read the crap I posted, basically I want the app to relaunch after x minutes of user inactivity. I tested a broadcast receiver briefly but my app closes with a finish() after one minute and it looked like it only worked if the app was in the foreground.
mrtech
so the flow is: runs for one minute, quits, then relaunch after x minutes of inactivity. I'm trying to hook into a schema to detect that inactivity.
mrtech
Going out on a limb, it sounds like you need to do some processing, which currently you do in your activity code. The problem with that, as you're noticing, is that activities can be purged from memory when no longer foreground. Especially when the screen is off. What you want to do instead is to offload processing to a service, which has a different lifecycle than an activity. You can actually make services run indefinitely. In Android, activities are only for interface: any processing should be done in a service.
Android Dev Dude
A caveat for this: when the screen is off, if you're doing any kind of processing, you want to acquire a PowerManager wakelock (partial, probably) and release it when you're done processing.
Android Dev Dude