Android 如何以最佳方式检查应用程序的状态?
我开发android应用程序。它需要保存Internet数据和登录/密码对。我需要在每项活动中检查这一点。如何以最佳方式做到这一点?我的解决方案: 我创建BaseActivity类:Android 如何以最佳方式检查应用程序的状态?,android,android-activity,Android,Android Activity,我开发android应用程序。它需要保存Internet数据和登录/密码对。我需要在每项活动中检查这一点。如何以最佳方式做到这一点?我的解决方案: 我创建BaseActivity类: public class BaseActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState)
public class BaseActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
checkRequirements();
}
private void checkRequirements() {
if (needToCheckInternetConnection())
checkInternetConnection();
//check other requirements
}
private void checkInternetConnection() {
if (!Updater.getInstance(context).checkInternetConnection()) {
Bundle data = new Bundle();
data.putSerializable(SplashScreenActivity.FIELD_ACTION, SplashScreenActivity.Action.SHOW_TEXT);
data.putString(SplashScreenActivity.FIELD_TEXT, getString(R.string.splashScreenInternetNotAvailable));
changeActivity(SplashScreenActivity.class, data);
}
}
protected void changeActivity(Class<?> goTo, Bundle data) {
Intent intent = new Intent(context, goTo);
if (data != null)
intent.putExtras(data);
startActivity(intent);
finish();
}
}
我扩展了所有的活动类
但是不要工作了。那么,如何更改该架构或强制使用finish方法?但finish不工作。-你能描述一下不工作意味着什么吗?它会崩溃吗?什么都不做?什么都不做。我搜索这个问题:但我的意思是这很糟糕。大量的额外代码。