0

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.

baldraider
  • 1,049
  • 2
  • 18
  • 48

2 Answers2

0

When i had the same issue, after a lot of research i added the below code in the styles.xml

<item name="android:windowDisablePreview">true</item>

Disable preview removes instant application launching but since you have splash screen then this should work.

Hope it helps you as well.

Johny
  • 625
  • 2
  • 6
  • 26
0

please build release mode or Disable Instant Run

I'd like to recommend to disable Instant Run

To disable Instant Run: Opens the Settings or Preferences dialog box. Go to Build, Execution, Deployment > Instant Run . Clear the check box next to Enable Instant Run .

redAllocator
  • 725
  • 6
  • 12