0

I've been working on an application recently and when I added some animations I started getting the Skipped XX frames, too much work on main thread warning. I optimized the images, moved as much as I could into AsyncTasks and I still get the warning. My onCreate function is as follows:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    userDetailsHandler = new UserDetailsHandler(this, null, null, 1);
    userDbHandler = new UserDBHandler(this, null, null, 1);
    userService = new UserServiceImpl();

    new IsLoggedIn().execute();

    setContentView(R.layout.activity_main);


    logo = (AppCompatImageView) findViewById(R.id.logo);
    Glide.with(this).load(R.drawable.logo).fitCenter().into(logo);

    container = (FrameLayout) findViewById(R.id.container);
    container.setVisibility(android.view.View.INVISIBLE);

    new FadeInAnimation().execute(container);

    loginFragment = new LoginFragment();
    registerFragmentOne = new RegisterFragmentOne();
    registerFragmentTwo = new RegisterFragmentTwo();
    facebookLoginFragment = new FacebookLoginFragment();

    getSupportFragmentManager().beginTransaction().add(R.id.container, loginFragment).commit();

    user = new User();
}

The logo drawable is a 74KB PNG. Why am I still getting the Too much work on main thread warning? Is it possible this happens because of some of the custom typefaces I'm using? Does the fact that I'm running it in an AVD add to the problem?

Andrej Naumovski
  • 573
  • 2
  • 9
  • 23
  • Could you log those messages to a file while running the app on a physical device? Or give it a run test on an android device – alvaro Mar 04 '17 at 19:26
  • May be you are blocking/awaiting for too long the UI Thread waiting for the async tasks to complete as pointed in [this answer](http://stackoverflow.com/a/14827618/1861742) – alvaro Mar 04 '17 at 19:33
  • @alvaro But I am not calling the .get() method of AsyncTask anywhere, and am not blocking the UI thread this way. I do all my processing in AsyncTasks and just update the UI in onPostExecute which runs on the UI thread. – Andrej Naumovski Mar 04 '17 at 19:46
  • Just to give you some ideas. I havent deal with androd dev. One more question if the onPostExecute is some kind of callback it should be ran by the async task. are you waiting for the async result somewhere in the UI thread?. As ive said just to give you some more ideas. – alvaro Mar 07 '17 at 00:07

0 Answers0