我有一个测验应用程序,它从 plist 文件加载问题数据库。当应用程序新加载时,它会运行一个线程来加载问题文件。
在一些不活动之后,当您再次打开应用程序并尝试运行新测验时,它不会加载任何问题。
我想它是操作系统用来清理一些内存的某种垃圾收集器,它正在完成它的工作,所以没关系。
但是你会推荐什么来重新加载文件?我在考虑覆盖 savedInstanceState?
这是启动屏幕和加载程序的组合,是第一个运行的活动
public class SplashScreen extends Activity {
/** Called when the activity is first created. **/
ProgressDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new LoadViewTask().execute();
}
private class LoadViewTask extends AsyncTask<Void, Integer, Void>{
//Before running code in separate thread
@Override
protected void onPreExecute(){
dialog = new ProgressDialog(SplashScreen.this);
dialog.setMessage("Loading...");
dialog.setTitle("Loading File");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();
}
//The code to be executed in a background thread.
@Override
protected Void doInBackground(Void... params){
try{
//Get the current thread's token
synchronized (this){
QuestionsLoader.getInstance(SplashScreen.this);
}
}
catch (Exception e){
e.printStackTrace();
Log.d("TAG", "exception" + e);
}
return null;
}
//Update the progress
@Override
protected void onProgressUpdate(Integer... values){
}
//after executing the code in the thread
@Override
protected void onPostExecute(Void result){
dialog.dismiss();
Intent i = new Intent("com.project.AnActivity");
startActivity(i);
finish(); //Finish the splash screen
}
}
}