I have a custom toolbar I have used in multiple activities (over 50 activities). The toolbar has an 'SOS' button. To add functionality to the 'SOS' button, one way would be to write same code for it's functionality in all my activities where I have used the custom toolbar. I would like to have my code for the functionality for toolbar 'SOS' button written only once. Is it possible to do this (by using a custom java file or something)?
An example would be appreciated.
Yes, you can do this by:
declare the onClick in XML of custom toolbar on button you want to perform the action
android:onClick="sosClick"
and then declare sosClick method into the BaseClass like this:
public abstract class BaseClass extends AppCompatActivity {
public void sosClick(View view) {
//Write your action here
//Toast.makeText(this, "SOS Pressed", Toast.LENGTH_SHORT).show();
}
}