0

I am very new for android and in my app,I have added fragment on activity when I tapped on button which is added on my fragment class I am getting warning on my log cat like below -

Skipped 91 frames! The application may be doing too much work on its main thread.

please help me how can I solve this?

BatchDetailsActivity:-

public class BatchDetailsActivity extends  AppCompatActivity  {

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

        //Intializing Fragments:-

        Intent i = getIntent();
        String fragment = i.getStringExtra("DetailsFragment_Key");

        intializingFragments(fragment);
    }

    private void intializingFragments(String fragmentType){

        android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        if (fragmentType.equals("BatchDetailsFragment")) {

            BatchDetails_Fragment fragment = new BatchDetails_Fragment();
            fragmentTransaction.add(R.id.fragment_container, fragment);
            fragmentTransaction.commit();

        }else if(fragmentType.equals("RaisePoDetailsFragment")){

            Rasing_po_Fragment fragment = new Rasing_po_Fragment();
            fragmentTransaction.add(R.id.fragment_container, fragment);
            fragmentTransaction.commit();
        }
    }
}

Rasing_po_Fragment:-

public class Rasing_po_Fragment extends Fragment implements AdapterView.OnItemSelectedListener {
    View view;

    Button select

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragment_raisepo_layout,container,false);

        select.setOnClickListener(buttonClickEvents());

        return view;
    }

 //Select and Cancel button implementation:-

    private View.OnClickListener buttonClickEvents(){
        return new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int getId = v.getId();

                if (getId == R.id.selectbuttonid){

                    Intent i = new Intent(getActivity(), PoFinalizaion.class);
                    getActivity().startActivity(i);
                }
            }
        };
    }
Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
Krish
  • 4,166
  • 11
  • 58
  • 110
  • Unrelated, but you don't need a method for the click listener. Replace what you have with `buttonClickEvents = new View.OnClickListener()... ` – OneCricketeer May 14 '16 at 14:40
  • is this solution to my question? – Krish May 16 '16 at 06:20
  • 1
    No? That's why I didn't put it as an answer. Besides, I don't see how this code you posted is giving you that warning. – OneCricketeer May 16 '16 at 06:23
  • when i tapped on select button i am calling PoFinalizaion class there i am displaying listview using custom adapter in this adapter class this waring is coming – Krish May 16 '16 at 06:28
  • Ok, then why did you show these activity and fragment classes that don't reference any adapter? – OneCricketeer May 16 '16 at 06:38
  • actually i am very new for android and i have done this in one sample application if u agree i will send this please see just 10 mins u can find problem is coming where – Krish May 16 '16 at 06:45
  • If you are pulling data into the listview from a SQLite database or from some server on the internet, then you should use an AsyncTask and I think the answer below already tells you that. – OneCricketeer May 16 '16 at 06:48
  • No No present just static data i am using for pulling data into listview and i am not using here "SQLite database or from some server on the internet" – Krish May 16 '16 at 06:52
  • if u see once u can easily find the solution – Krish May 16 '16 at 06:53
  • I don't understand what you are asking of me. If your app isn't having problems and you are only starting to learn to write apps, then I wouldn't worry about that warning. – OneCricketeer May 16 '16 at 06:56

1 Answers1

2

I think this can help you. I think Use uiThread will clear this warning. In Your Activity, use this code:

new Thread(new Runnable() {
  @Override
  public void run() {

    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        //your code or your request that you want to run on uiThread
      }
    });
  }
}).start();