Hi,
I am currently facing the following problem: whenever my Android application is started, it needs to execute some time consuming initialization code. Without this code all my activities/services within the application won't work correctly.
So far, I have put this initialization code into a SplashScreen activity, which I declared as MAIN activity in the manifest. Once the initialization code has been executed, I finish() the splash screen and start the actual main activity, i.e. an activity consisting of several tabs, from where the user can reach several other activities.
The problem is now the following: when my app is put in the background, after some time and after launching other apps, my app/process is killed. When I re-launch it from the homescreen, Android restores the activity stack (task) and invokes onCreate() on them. However, the splash screen activity and hence the initialization code aren't executed, which results in an exception.
I could put now the initialization code in the application's onCreate(), however this results in a black screen until the method finishes.
Does anybody have an idea, where and how I can properly initialize my app on startup?
Initialization code:
public void init() {
if (initialized) {
return;
}
// Initialize terms
List<Tag> tags= DynamicDao.loadAll(Tag.class);
int numTags = tags.size();
terms = new String[numTags];
for (int i = 0; i < numTags; i++) {
terms[i] = tags.get(i).getTag();
}
// Initialize document-term matrix
List<Item> items = DynamicDao.loadAll(Item.class);
createDocumentTermMatrix(items);
initialized = true;
}
Note: An Item has several associated tags, from which I need to create a document vector.