0

I was going through this tutorial , in which they created a abstract class which extends ListActivity called AbstractListViewActivity. This class is then used in the following way:

public class EndlessListViewActivity extends AbstractListViewActivity
{

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.endless);
    datasource = Datasource.getInstance();
    footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer, null, false);
    getListView().addFooterView(footerView, null, false);
    setListAdapter(new CustomArrayAdapter(this, datasource.getData(0, PAGESIZE)));
    getListView().removeFooterView(footerView);

AbstractListViewActivity also contains a AsyncTask inner class which is then used in EndlessListViewActivity . Why is an abstract class used here? For what purpose ?

I tried to look at some documentation but that didnt help

1 Answers1

4

If you look at the source for the tutorial, it shows there's no abstract methods, so the abstract keyword here is used simply to ensure you can't add the AbstractListViewActivity without extending it.

The reason for this, as Ankur Shanbhag so eloquently writes, is:

Abstract class means the definition of the class is not complete and hence cannot be instantiated. Even though it does not have abstract method, it is an indicator that the class is available for inheritance. Even though it has implementation for all the methods in it, the implementation may still not be complete and must be overridden by the extending class.

Note that the example activity extends ListActivity, which according to the source itself extends Activity - and neither ListActivity nor regular Activity are abstract.

Community
  • 1
  • 1
Adam S
  • 16,144
  • 6
  • 54
  • 81