title: How to get Display object from my service class?
body: <p>Because many of my Activities need to check the screen size with the following code:</p>
  
  <pre><code>Display display = getWindowManager().getDefaultDisplay();
  int screenWidth = display.getWidth();
  int screenHeight = display.getHeight();
  </code></pre>
  
  <p>I decide to move this code from each activity class to a service class, so that the code can be defined in one place and invoked by every activity class.</p>
  
  <p>So, I made my service class like below:</p>
  
  <pre><code>public class MyService {
  
       private  Display display;
       public int screenWidth, screenHeight;
  
       public MyService(){
           display = getWindowManager().getDefaultDisplay(); //Error here
  
           screenWidth = display.getWidth();
           screenHeight = display.getHeight();
  
       }
  
       public int getScreenWidth(){
            return this.screenWidth;
       }
  }
  </code></pre>
  
  <p>Because my service class does not extends <code>Activity</code>, I can not directly use <code>getWindowManager()</code>. I would like to know how to get rid of this problem to have the <code>Display</code> instance in my service class which is not necessary to extends Activity class?</p>
  
  <p>That's I would like my activity can access the screen width like following:</p>
  
  <pre><code>public class MyActivity extends Activity{
  
    MyService service;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
  
         service= new MyService();
  
         int sWidth = service.getScreenWidth();
      }
  
  }
  </code></pre>