Get Help And Discuss STEM Concepts From Math To Data Science & Financial Literacy
STEM Gender Equality | Join us on ZOOM | Spreading Mathematical Happiness | Join Us on Slack

MathsGee is free of annoying ads. We want to keep it like this. You can help with your DONATION

0 like 0 dislike
23 views
What is the procedure to check status of an activity in Android?
in Computer Science by Diamond (51,000 points) | 23 views

1 Answer

0 like 0 dislike
Best answer

You can use a static variable within the activity.

class MyActivity extends Activity {
     static boolean active = false;

      @Override
      public void onStart() {
         super.onStart();
         active = true;
      } 

      @Override
      public void onStop() {
         super.onStop();
         active = false;
      }
}

 

The only gotcha is that if you use it in two activities that link to each other then onStop on the first is sometimes called after onStart in second. So both might be true briefly.

Depending on what you are trying to do (update the current activity from a service?). You could just register a static listener in the service in your activity onStart method then the correct listener will be available when your service wants to update the UI.

by Diamond (51,000 points)

Related questions

0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
asked May 12 in Data Science by Tedsf Diamond (51,000 points) | 18 views
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Aug 29, 2019 in Computer Science by Tedsf Diamond (51,000 points) | 19 views
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
asked Sep 1, 2019 in Computer Science by Tedsf Diamond (51,000 points) | 14 views

Welcome to MathsGee Q&A Bank, Africa’s largest personalized STEM and Financial Literacy education network that helps people find answers to problems, connect with others and take action to improve their outcomes.


MathsGee Q&A is the STEM and Financial Literacy knowledge-sharing community where students and experts put their heads together to crack their toughest questions.


MathsGee is free of annoying ads. We want to keep it like this. You can help with your DONATION

Enter your email address:

11,819 questions
9,828 answers
100 comments
10,516 users