Android: onResume() in main activity
<p>This question is based on <a href="http://stackoverflow.com/questions/3262157/how-to-check-if-my-activity-is-the-current-activity-running-in-the-screen">this older one</a> (not by me).</p>

<p>I need to run the following code on my main activity (the one that launches first when I open my app):  </p>

<pre><code>public static boolean isInFront;

    @Override   
    protected void onResume() {
        //isInFront = true;
    }

    @Override
    protected void onPause() {
        //isInFront = false;
    }
</code></pre>

<p>The problem is, onResume() causes my app to crash when I open it. As I understand it, this is what should happen because onCreate() should be called for the first activity the app runs (I also have that function later in my code).</p>

<p>But I really need this bit of code there to tell me when the main activity is the one currently active/in the foreground.</p>

<p>Is there any way to fix this so that I can keep onResume() in my main activity without running it instead of onCreate() when the app starts? Many thanks!</p>
