Call a method of "Activity extended" class from "ListActivity extended"

253 views Asked by At

Here is the snippet of "MyBaseActivity" Class.

public class MyBaseActivity extends Activity {
      public void resetDisconnectTimer()
       {
         disconnectHandler.removeCallbacks(disconnectCallback);
         disconnectHandler.postDelayed(disconnectCallback, DISCONNECT_TIMEOUT);
       }

       @Override
        public void onUserInteraction()
       {
           resetDisconnectTimer();
        }
 }

My App contains many classes that extend "Activity" and couple of others extend listActivity. For the classes, extending Activity, I can just extend the "MyBaseActivity" and call the method as:

     @Override
     public void onUserInteraction() 
    {
        resetDisconnectTimer();
    }

But what about for the classes that extending listactivity ? Any ideas how we can solve it ??

1

There are 1 answers

0
Alexander On

You can switch to fragments so:

class MyActivity extends MyBaseActivity { 
@Override protected void onUserInteraction() {..}
}

class MyBaseActivity extends FragmentActivity {
protected void onUserInteraction() {...}
}

Then you some of your subclasses of BaseActivity have a ListFragment in them. To make the porting easier assign id of @android:id/list to that ListFragment.