I have a dilemma, basically I have ImageButtons that I want to be displayed on all activities (this is done) and I also want them to be displayed on all activities a certain way, depending on which activity is being displayed. I want this to be done in a way that I don't have to hardcode the specifications individually in each class.
Although the images are defined in one shared XML document, I want a shared class to be able to read which activity is being called, and then format a particular image a certain way. This is so if I change the functionality, I only have to change attributes in one class.
I want to do some sort of If or switch statement that compares if( thisActivity == MainActivity ) then, but I don't know how to retrieve the "names" of the activities to compare them!
edit. I want something like this:
Context myContext = this;
if(myContext instanceof Intent(MainMenu.class) == true)
{
}
I know the Intent function doesn't have a prototype to check a class like that, but I want something that will let me know the current class is part of a particular class, as opposed to several other cases in the conditional statement
thank you for any insight!
Use this. getClass(). getSimpleName() to get the name of the Activity.
An activity represents a single screen with a user interface just like window or frame of Java. Android activity is the subclass of ContextThemeWrapper class. The Activity class defines the following call backs i.e. events. You don't need to implement all the callbacks methods.
Will the instanceof
operator suit your needs?
if(this instanceof Activity1) {
//...
}
else if(this instanceof Activity2) {
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With