Am I doing it right?
I have a Splash screen (just an image), and onCreate() I start the main activity after running a heavy function:
SPLASH_DISPLAY_LENGHT=2500;
new Handler().postDelayed(new Runnable(){
public void run() {
LONG_OPERATING_FUNCTION();
Intent mainIntent = new Intent(this, MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
I think I have a memory leak, and I’m trying to find it.
I don’t think the Splash really is finishing.
LONG_OPERATING_FUNCTION()should not be done on the main application thread, as you have it here.Ideally, you do not use a splash screen, but rather only enable selected features of
MainActivitywhile do yourLONG_OPERATING_FUNCTION()in anAsyncTaskor something.If somebody is pointing a gun at your head and forcing you to implement a splash screen lest it be your brains that get, er, splashed, I would do this:
HandlerandpostDelayed()callAsyncTaskdoInBackground()ofAsyncTask, do yourLONG_OPERATING_FUNCTION()LONG_OPERATING_FUNCTION()is done,SPLASH_DISPLAY_LENGHT[sic] time has not elapsed, useSystemClock.sleep()to sleep for the remaining time (or not)onPostExecute(), startMainActivityand callfinish()