0

I have a simple layout which contains LaunchFragment. Pressing a button in LaunchFragment replaces it with a MapFragment as follows:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map_test);

    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_view, new LaunchFragment()).commit();
}

@Override
public void onTriggerReplace(int id) {
    switch (id){
        case R.id.btn_replace_google:
            launchGoogleMapsFrag();
            break;
    }
}

private void launchGoogleMapsFrag() {
    FragmentManager fm = getFragmentManager();
    fm.beginTransaction().replace(R.id.content_view, MapFragment.newInstance()).commit();
}

Note: onTriggerReplace(int) is invoked by the launch fragment. The code pasted above resides in the activity which is hosting the fragments.

The problem is that the replace causes the following warning:

01-10 01:12:18.575  27820-27820/com.test.mapsprototype I/Choreographer﹕ Skipped 83 frames!  The application may be doing too much work on its main thread.

The delay is quite noticeable. Is there any way around it?

What I already know:

  • Starting a new activity (which will have the map fragment) from launch fragment does not show this warning however my requirements prevent me from doing so.

Update (Requirement(s)): The only requirement I need to satisfy is have it integrate into a bigger application which already does the fragment replace for me as long as I provide it with the fragment so I don't have the option to launch another activity. All the other fragments seem to work fine but the map fragment causes the frame skipping.

Naveed
  • 2,942
  • 2
  • 25
  • 58
  • What you seem to be doing looks pretty standard. Nothing wrong with it unless you're actually doing something heavy on the UI thread which is not related to Fragments' transitions. So If you could specify the requirement you mentioned, may be people will be able to solve your problem at the application's design level. – Varun Singh Jan 10 '15 at 07:06
  • Hey see the update. I know it is a very standard operation and there is nothing going on ui thread besides the replace thats why I was confused on why it would be causing this error. I tested this by creating a separate app just having 2 fragments. One initial one which has the button to launch google maps fragment. I am pretty sure anyone who uses a map fragment like this would have the error. I was just looking for work around. I can post the entire demo app code here if you want to run it your self to see the error – Naveed Jan 10 '15 at 18:09

0 Answers0