I have activity A that needs to do things upon exit
-Save stuff to a database
-Start Activity B
As saving can take a while, i though i should start a new thread to have the database access running in the backgroud, while the user is busy reading the content of activity B. (B does not use the saved data btw).
So I have in Activity A
FinishStuff(){
Intent ourIntent = new Intent(this, ActivityB.class);
startActivity(ourIntent);
handler = new Handler();
handler.post(dbSaver);
}
public Runnable dbSaver = new Runnable() {
@Override
public void run() {
saveToDbs();
}
Howevever, What happens is that OnCreate() of activity B is called immediately, but the screen space where my new Activity should go is black until, saveToDBs() is finished at which stage Activity B gets displayed.
Any way to solve this?
TIA
You have mistaken
HandlerbyThread.The
Handlercan be used by threads to run a piece of code in another thread (i.e update UI, inform progress, etc.) and what you need is a new thread.So, you need to replace:
by:
Regards.