Reputation: 47
I have write a splash activity as I search like this
public class SplashActivity extends Activity{
private Utility utility;
private static final long SPLASH_TIME = 2000;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
context = this;
utility = Utility.getInstance();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
utility.fillDatabase(context);
Intent intent = new Intent(context,MainActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_TIME);
}
}
as you can see I have utility.fillDatabase() in my run method and my delay time is 2 second but I need to rewrite my splash activity finish after all of task was done not after specific time. please help me to make an idea.
Thanks
Upvotes: 1
Views: 82
Reputation: 111
Use an AsyncTask .
Do your job at doInBackground -utility.fillDatabase(context);
And hide / finish the splash only at onPostExecute
Upvotes: 2