Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:27:05+00:00 2026-06-09T15:27:05+00:00

This question is based on this older one (not by me). I need to

  • 0

This question is based on this older one (not by me).

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

public static boolean isInFront;

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

    @Override
    protected void onPause() {
        //isInFront = false;
    }

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).

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

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:27:06+00:00Added an answer on June 9, 2026 at 3:27 pm

    You can have both methods, it’s your code that is crashing it. You should check out the activity lifecycle.

    Is that your only code? Do you call super.onResume() and super.onPause() in their methods?

    public static boolean isInFront;
    
        @Override   
        protected void onResume() {
            super.onResume();
            isInFront = true;
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            isInFront = false;
        }
    

    Sorry if I misunderstood your question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is based on this thread . The code function man() { man
First of all, this is not really a programming question. It's more a question
This question is a spin-off from this one . Some history: when I first
This question is based on my previous question which I got a working answer
This question is based on the thread . I have the shell function function
This question is based on this thread . Is [---] a comment in Git
This question is based on this thread . I am interested in how Git
This question is based on this thread in Meta . I would like to
This question is based on this thread . Problem: to access MySQL's manual when
This question probably is based on my lack of understanding of the role of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.