最初,“启动”屏幕可以运行,但是当我添加更多代码(下面的代码中的if语句)时,它停止出现。
代码需要调用AsyncTask类。我尝试将if语句移到调用SQLiteHelper的AsncTask上。没用我读了一些与此有关的文章,发现其中无法从AsynTask调用SQLiteHelper。
在启动Splash期间,我需要下载一个不存在的文件,然后将其保存在SQLite中,最后从SQLIte获取文件的数据。
public class SplashActivity extends AppCompatActivity {
String fileName = "movies.json";
static String appName = "JSONApp";
String path = getExternalStorageDirectory() + "/" + appName + "/" + fileName;
ArrayList<Movie> moviesList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
File file = new File(path);
//checking if movies.json exists
if (file.exists()) {
Log.d(TAG, path + " exists");
moviesList = new JsonToSQLiteHelper(this).getMovies();
toMainActivity(moviesList);
}
else if (!shouldCheckPermission()) {
Log.d(TAG, "The JSON file doesn't exists");
Log.d("", "permission was already granted");
moviesList = FromJsonToSQLite();
toMainActivity(moviesList);
} else {
if (shouldCheckPermission()) {
Log.d("", "Permission was checked.");
requestPermissionAndContinue();
Log.d("", "permission was denied");
} else {
Log.d("", "permission was denied and then given?");
moviesList = FromJsonToSQLite();
toMainActivity(moviesList);
}
}
}
答案 0 :(得分:0)
飞溅没有等待时间。因此,它将直接导航到主屏幕。您可以放置一个计时器并设置等待时间。如果您使用asynctask,请共享代码。