0
我必須編寫一個代碼來顯示「internet not available」對話框在幾個類文件中。據我所知,我需要寫這個代碼onCreate方法而已,但我的關注點是,代碼重複執行。的代碼如下代碼重複
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(...................)
{
}
在幾類文件相同的代碼將被repeted。爲了避免這種情況,如果我編寫單獨的類文件並將其擴展爲「Extends」,那麼我擔心onCreate方法將通過所需的類文件重寫,其中包含其他內容。
有任何建議。