views:

54

answers:

2

Hi Guys though i got the Screen Size by using the following from a activity,

Display display = getWindowManager().getDefaultDisplay();

But the same thing is not working from a service (for obvious reasons, i know!) but i desperately need to get the display size from a service. Can some1 please explain me any other way for getting the ScreenSize??

So i guess as far as i see, there is no way we can get the Screen size from the service. Wat i have done as of now is to start the activity atleast 1ce by default and store the actual screen size in pixels in the shared preferences. I use the shared preferences to get the value when the service starts.

Is this the only way it'll work out??? Cant we by any means get the screen size from the service??

A: 

Ok Guys I guess there is really no way to obtain the Screen Dimensions using a service! I have currently accessed the screen dimensions by saving the dimensions in the Shared Preferences when the activity is started the first time. Later when the service has to use it, it can access the dimensions from the shared preferences... Guess this is the only way out as of now... Thanx all for your valuable help!!!

JaVadid
If you are starting the service on boot (or automatically any other way) then shared prefs is a good way. However, if the only way you start the service is thru calling `Context.startService()` then it actually makes more sense to just place an extra in the Intent that you use to start the service.
Hamy
A: 

If you are starting the service on boot (or automatically any other way) then shared prefs is a good way. However, if the only way you start the service is thru calling Context.startService() then it actually makes more sense to just place an extra in the Intent that you use to start the service. – Hamy 18 secs ago edit

Hamy
Well Thanx a lot Hamy, but the service is more of a scheduled kind... i Don decide when it starts, the user decides the timing... Hence cant pass the information in intents... Thanx for your reply buddy... was dying to hear from some1 other than myself about ideas i can implement!
JaVadid
secondly correct me if i am wrong but i have heard that in case of services, the intent extras cannot be retrieved... don kno whether its true coz never tried it...
JaVadid