When I open my app for debugging on my device it shows white blank page for around 1-2 sec then my splash screen is shown. I read about this problem on android developer website that says it may be causes due to heavy app initalization in application subclass.
My application extended class code is here :
public class MyApplication extends Application{
private static ApplicationComponent mApplicationComponent;
@Override
public void onCreate() {
super.onCreate();
FacebookSdk.sdkInitialize(getApplicationContext());
if (mApplicationComponent == null){
mApplicationComponent = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this)).build();
}
}
public static ApplicationComponent providesApplicationComponent(){return Preconditions.checkNotNull(mApplicationComponent);}
}
My splash Screen Code : -
public class SplashActivity extends AppCompatActivity {
@BindView(R.id.splash_screen)
ImageView mSplashScreen;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ButterKnife.bind(this);
Picasso.with(this).load(R.drawable.bg_splash_screen).fit().centerCrop().into(mSplashScreen);
SharedPreferences mSharedPreferences = getSharedPreferences(Constants.PREFERENCE,MODE_PRIVATE);
if (mSharedPreferences.getBoolean(Constants.LOGGEDIN,false)){
Intent homeIntent = new Intent(this, HomeActivity.class);
openPage(homeIntent);
} else {
Intent signupIntent = new Intent(this, SignUpActivity.class);
openPage(signupIntent);
}
}
private void openPage(final Intent intent){
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(intent);
finish();
}
},1200);
}
}
I'm doing only this two initialization in my application class. Is this is the problem ? If or If not How to solve this problems.