I have a set of 3 functions which i uses in 3 activity classes. Instead of putting the 3 methods in each of the 3 classes, how can i write the 3 methods only once and then call these methods in all other classes…
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.icon:
settingBoard();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void settingBoard() {
Log.i(MY_DEBUG_TAG, "Preparing settings page..");
/*
* progressDialog.setMessage("Preparing settings page.....");
* progressDialog.show();
*/
Intent lma = new Intent(this, SettingsActivity.class);
startActivityForResult(lma, 3);
}
Any help is appreciated
Write an abstract Activity subclass that contains these three functions. Then derive your three Activity classes from the abstract class.