Last active
February 26, 2019 09:33
-
-
Save pratikbutani/0fc33807045a913ce0251fbce873914a to your computer and use it in GitHub Desktop.
Common Activity for all Activities (using DataBinding)
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
public abstract class BaseActivity extends AppCompatActivity { | |
/** | |
* DataBinding Object | |
*/ | |
private ViewDataBinding mBindingObject; | |
/** | |
* Context common | |
*/ | |
public Context mContext; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mBindingObject = DataBindingUtil.setContentView(this, getLayoutResId()); | |
mContext = this; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
Window window = getWindow(); | |
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | |
window.setStatusBarColor(getResources().getColor(R.color.colorPrimary)); | |
} | |
init(); | |
} | |
/** | |
* Get Layout Resource ID | |
* @return Layout Id | |
*/ | |
public abstract int getLayoutResId(); | |
/** | |
* Initialization for members | |
*/ | |
public abstract void init(); | |
/** | |
* Getting Binding Object | |
* @return Binding Object | |
*/ | |
public ViewDataBinding getBindingObj() { | |
return mBindingObject; | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
try { | |
Runtime.getRuntime().gc(); | |
System.gc(); | |
} catch (Exception ignored) { | |
} | |
} | |
} |
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
public class SplashActivity extends BaseActivity { | |
ActivitySplashBinding mBinding; | |
@Override | |
public int getLayoutResId() { | |
return R.layout.activity_splash; | |
} | |
@Override | |
public void init() { | |
mBinding = (ActivitySplashBinding) getBindingObj(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment