in my app user needs to authenticate before he can start using the app..
I have this code in startupActivity
private boolean checkAuthentication() {
SharedPreferences sp = getSharedPreferences(
"com.simekadam.blindassistant", Context.MODE_PRIVATE);
return sp.getBoolean("logged", false);
}
private void processStartup(){
Log.d(TAG, "processing startup");
if (checkAuthentication()) {
Intent startApp = new Intent(getApplicationContext(),
BlindAssistantActivity.class);
startActivity(startApp);
} else {
Intent loginIntent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(loginIntent);
}
}
it just works but I need to check it propably in every activity (in onStart or onResume methods), but it would cause code duplications among all my activities. What is the best way how to do this? Can I create a masteractivity which will be extended with other activities?
thanks
Yes you can create a master Activity and use “extends” to inherit from it, however I’d look into AppState if I were you.
You can create a class that extends the Application class. You can then use this for “global” variables and states.
Check out this webpage:
http://www.helloandroid.com/tutorials/maintaining-global-application-state