Java how to get context in PageAdapter in getCount()?
<p>I'm working on a home replacement app and I need to get the context to access shared preferences and get the number of screens my app should have to use it on getCount().</p>

<p>I've banging my head against the wall for the last few hours but I cannot figure out how to get the context before getCount() is fired.</p>

<p>This is my code:</p>

<pre><code>public class MyPagerAdapter extends PagerAdapter {
    public Context context;

    public int getCount() {
        return 5;
    }

    @Override
    public Object instantiateItem(View container, int position) {
        Context context = container.getContext();
    }
</code></pre>

<p>I'm getting the context on instatiateItem but instatiateItem runs after getCount(), is there a way to get the context directly on the pageAdapter? Or how can I run getContext() before getCount() is fired?</p>
