Last active
September 27, 2017 08:28
-
-
Save aqua30/6d217c5e33dd64eb93265e8a36135be9 to your computer and use it in GitHub Desktop.
Hide the view binding using ButterKnife and Abstraction.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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