应用程序可能在其主线程上做了太多工作

时间:2016-05-14 09:44:43

标签: android

我是Android的新手,在我的应用程序中,当我点击我的片段类上添加的按钮时,我在活动中添加了片段我在我的日志猫上收到警告,如下所示 -

跳过91帧!应用程序可能在其主线程上做了太多工作。

请帮助我如何解决这个问题?

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);
                }
            }
        };
    }

1 个答案:

答案 0 :(得分:0)

我认为这可以帮到你。我认为使用uiThread会清除此警告。在“您的活动”中,使用以下代码:

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();