Reputation: 489
I have to write a code to show "internet not available" dialogue box in few class files. As far as i know i need to write this code onCreate method only, but my concern is, code repetition. The code is as follows
onCreate()
{
if(isNetworkStatusAvialable (getApplicationContext()))
{
showAlertDialog(HomeActivity.this, "Internet Connection",
"You have internet connection", true);
}
else
{
showAlertDialog(HomeActivity.this, "No Internet Connection",
"You don't have internet connection.", true);
}
}//End of oncreate
showAlertDialog(................... )
{
}
In few class files the same code will be repeted. To avoid this, if i write separate class file and extend as "Extends" then i worried that onCreate method will be override through out the required class files, which consists of other things.
Any suggestions.
Upvotes: 0
Views: 53
Reputation: 134664
The application will crash with a SuperNotCalledException
if an Activity overrides onCreate()
without calling through to super.onCreate()
, so as long as each Activity extends your base Activity you can be guaranteed that your implementation will be called.
Upvotes: 1