-2

I would like to somehow check if the activity is open. I have got activity1.java and activity2.java. If the user will open activity 1, textview will be green else textview will be blue(I know how to change background dynamically). I want to do it this way!

If (activity1 is open) {
    tv.setBackgroundColor(COLOR.GREEN);
} else if(activity2 is open) {
    tv.setBackgroundColor(COLOR.BLUE);
}
Gladhus
  • 910
  • 1
  • 13
  • 24
user3297991
  • 9
  • 1
  • 4
  • possible duplicate of [Android: how do I check if activity is running?](http://stackoverflow.com/questions/5446565/android-how-do-i-check-if-activity-is-running) – Bosko Mijin Apr 09 '14 at 12:59
  • Here is the solution: http://stackoverflow.com/questions/5446565/android-how-do-i-check-if-activity-is-running. You can have static members or try to get from Activity.class compared with getCanonicalName() value. All is displayed here in several examples. – Bosko Mijin Apr 09 '14 at 13:02

2 Answers2

0

You should keep a global variable in your Activity, for example boolean isVisible. Then in your onResume() you set

isVisible = true

and in the onPause() method

isVisible = false
Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
0

just make a string variable in any activity lets say i make it on activity3 like

public static String activity_name=null;

on activity1 put a value like

activity3.activity_name = first;

on activity2 put a value like

activity3.activity_name = second;

now just check

if (activity3.activity_name.equals("first") && !activity3.activity_name.equals(null))
{
    tv.setBackgroundColor(COLOR.GREEN);
}
    else if(activity3.activity_name.equals("second") && !activity3.activity_name.equals(null))
{
    tv.setBackgroundColor(COLOR.BLUE);
}