当我的应用程序安装并首次打开时(当有互联网连接时)我希望手机从我的服务器下载一些信息并将其插入数据库。
如果信息没有完全下载或根本没有下载,这个 Activity 应该发生直到它完全下载?
我该怎么做呢?
最佳答案
使用偏好
在你的 Activity 中:
private boolean isFirstLaunch() {
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean isFirstLaunch = settings.getBoolean("isFirstLaunch", true);
Log.i(TAG + ".isFirstLaunch", "sharedPreferences ");
return isFirstLaunch;
}
从onCreate
调用
if (isFirstLaunch()) {
Intent firstLaunchIntent = new Intent(this,
GetStartedActivity.class);
firstLaunchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(firstLaunchIntent);
// set the bool to false in next activity !
finish();
}
关于java - android应用首次启动时如何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6374059/