0

I'm currently using a long running service as a timer that can last up to 4 hours. The activity that calls the service usually gets destory when its in the background for awhile. When the service is finished its task, it calls the activity back to the foreground. The service then sends a boardcast to the activity that it has finish and the activity then plays an alarm.

The issue is the activity uses an alert dialog to display the opition to stop the alarm but since the activity was perviously "dead" it needs to go through the onCreate phase. I get an error because the alert dialog which is tiggered from the broadcast reciever is trying to display before the layout has actually finished creating and displaying its self. I get a force close and the window manager error.

How can I my alert dialog wait until the layout is displayed and the onCreate method is finished?

VirtualProdigy
  • 1,657
  • 1
  • 19
  • 34
  • I think you should show us some code for more accurate answer. First, in which method you display dialog? Have you tried to show dialog on steps after onCreate phase, like onStart, onResume? – marwinXXII Jun 13 '12 at 15:06

1 Answers1

0

I would approach this situation by using the notification service. The notification can be set up so when it is clicked on the activity would be started and you can pass a value to flag for the dialog to be displayed. This link should be helpful : Sending a notification from a service in Android

You can then initiate the dialog in the onResume method.

Community
  • 1
  • 1
Proxy32
  • 681
  • 5
  • 17