We are using the Thread of a common base class but using its handler in all its sub classes. The code is working fine but is it the right way to go about?
Our base class looks like this:
public class BaseActivity extends AppCompatActivity {
public Handler mHandler;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Try to reuse the activity handler. If null, create new.
mHandler = getWindow().getDecorView().getHandler();
if (mHandler == null) {
mHandler = new Handler();
Log.w(TAG, "failed to reuse activity handler");
}
}
}
And we are using this instance of handler in all the activities which extend from BaseActivity
. We have not faced any issues. No task in the sub classes is very long. Could this be done any better?