Skip to content

Instantly share code, notes, and snippets.

@aqua30
Last active September 27, 2017 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aqua30/6d217c5e33dd64eb93265e8a36135be9 to your computer and use it in GitHub Desktop.
Save aqua30/6d217c5e33dd64eb93265e8a36135be9 to your computer and use it in GitHub Desktop.
Hide the view binding using ButterKnife and Abstraction.
/**
* Created by Saurabh(aqua) on 21-03-2017.
*/
public abstract class BaseActivity extends AppCompatActivity implements LifecycleRegistryOwner {
private LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);
private Unbinder unbinder;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getActivityLayout());
unbinder = ButterKnife.bind(this);
}
@Override
public LifecycleRegistry getLifecycle() {
return lifecycleRegistry;
}
@Override
protected void onDestroy() {
super.onDestroy();
unbinder.unbind();
}
protected abstract int getActivityLayout();
}
/**
* Created by Saurabh(aqua) in 2017.
*/
public class TestActivity extends BaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected int getActivityLayout() {
return R.layout.ac_test;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment