mobilGelistirici
mobilGelistirici

Reputation: 449

How to see child Activity from its ancestor, in Android Java Programming?

I know this question does not make great sense, but somehow I think that its not impossible.

I have defined a "base" class, where all the other activities extend it. Like this:

public class ExtendedActivity extends Activity 
{
}

public class Activity1 extends ExtendedActivity
{
}

public class Activity2 extends ExtendedActivity
{
}

So I need to call a method in ExtendedActivity 's onCreate method, only if the current Activity is not Activity1

How can I manage that ? Thanks for any help.

Upvotes: 0

Views: 70

Answers (1)

Amulya Khare
Amulya Khare

Reputation: 7708

Lets say you have classes as follows:

public class ExtendedActivity extends Activity 
{
    protected void method1() {
    }
}

public class Activity1 extends ExtendedActivity
{

}

public class Activity2 extends ExtendedActivity
{
}

You can call method1() only if currentActivity is NOT Activity1 as follows:

 Activity currentActivity = this;   
 if(!(currentActivity instanceof Activity1)) {
        currentActivity.method1();
 }

Upvotes: 3

Related Questions