Hello all: So, I'm trying to write my activities in such a way as to save their state if they ever get killed and restarted, and I've come across an interesting dilemma when working with the AlarmManager.
So the way my alarm Activity works is: 1. Set time button: launches time picker dialog that is set to the current time (based on Calendar). Whatever time is chosen here becomes the time the user wants the alarm to go off. 2. Radio buttons: let the user choose an audio file (in my case a stream) that they want to play when the alarm goes off 3. Set Alarm button: calculates which day the alarm is for based on what time was chosen (will either be later today or tomorrow) and then calculates the offset in epoch time for the alarm manager. Next it creates the intent and pending intent for use with the Alarm Manager. Then it sets a flag (true) that the alarm was set and uses a Toast message to tell the user the alarm is set and for what time (this sounds like a lot and may need to go in a background task) 4. Cancel alarm button: cancels the alarm obviously :) So in my onSaveInstanceState method I'm saving all of the integers and strings that I used for my calculations and the flag of whether or not the alarm has been set. Then in the onCreate method I check to see if the saved bundle is null, if not I get all my data back out. Then, I check to see if the alarmIsSet flag is true...if so, I go ahead and re-create the intent and Pending intent and use the alarm manager to set the alarm with my saved values....the only way the alarmIsSet flag will be true is if the Set Alarm button was clicked before the activity was destroyed and re-created...otherwise it will always be false. So, on to my problem. If I set the time and set the alarm and then let it sit...it works totally fine....It launches my activity that handles the alarm (basically just plays one of the streams with a stop alarm button). However, if I set up my time and click set alarm and then change the orientation, or if i set the time, change the orientation and then set the alarm...when it gets time for the alarm to go off it doesn't do anything. Then I found the following messages in the LogCat: startActivity called from non-Activity context, forcing Intent FLAG_ACTIVITY_NEW_TASK for Intent (name of my intent) Activity pause timeout for HistoryRecord Launch timeout has expired, giving up wake lock I don't understand how the first message can be possible...if the activity is getting recreated after the orientation change, and the intents are either created or re-created, how can it be a non- activity? Now I plan to actually stop orientation changes from re-starting my activities, but I wanted to be able to save the state in case the activity gets killed by an incoming phone call or something else...so I'm using the orientation change as a way to test my save state code. My app uses a tab layout with a tabhost...and I've noticed that it doesn't matter what tab I'm on when I change the orientation, but all of the activities are getting re-created...Also the back button will close the app instead of going back to a previous tab (if there is one) when you click it. Correct me if I'm wrong, but this leads me to believe that even though all my tabs open separate activities, they are all considered one activity because of the tab host. Unless the back button will back track through tasks in which case this behavior is correct since all my activities are all part of the same task. Anyway...any help that can be provided is much appreciated. Thanks, DanielleM -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en