Skipped 320 frames doing too much on its main thread
<p><strong>Edit</strong></p>

<p>The Main issue was in the fragment I opened with the eventbus. I introduced delay over there which caused the issue. Anyway thanks for the help.</p>

<p><strong>Main Post</strong></p>

<p>Yet another skipped frames question. So here is my code</p>

<pre><code>public class ProductDisplayAdapter extends RecyclerView.Adapter&lt;ProductDisplayAdapter.ViewHolder&gt; {

    private Context context;
    private List&lt;Item&gt; productList;
    private Table&lt;String,Integer,Item&gt; cartTable = HashBasedTable.create();
    private OnItemChanged itemChangedListener;
    private ViewHolder viewHolder;
    private Picasso picasso;
    public ProductDisplayAdapter(Context mContext, List&lt;Item&gt; items)
    {
        this.context = mContext;
        this.productList = items;
        this.picasso = Picasso.with(context);
        this.picasso.setIndicatorsEnabled(true);
    }

    private Item getItem(int position) {
        return new Item(productList.get(position));
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(context).inflate(R.layout.list_product,parent,false);
        this.viewHolder = new ViewHolder(view);
        viewHolder.cartAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                viewHolder.numberButton.setNumber("1");
                viewHolder.viewSwitcher.showNext();
                if(itemChangedListener != null)
                {
                    int position = viewHolder.getAdapterPosition();
                    Item product = productList.get(position);
                    product.setTotalQuantity(1);
                    notifyItemChanged(viewHolder.getAdapterPosition());
                    productList.set(position, product);
                    cartTable.put(product.getId(), product.getMetricPosition(), product);
                    itemChangedListener.onItemAdded(cartTable, 1);
                }
            }
        });
        viewHolder.numberButton.setOnValueChangeListener(new ElegantNumberButton.OnValueChangeListener() {
            @Override
            public void onValueChange(ElegantNumberButton view, int oldValue, int newValue) {
                if(itemChangedListener != null)
                {
                    int position = viewHolder.getAdapterPosition();
                    Item product = productList.get(position);
                    product.setTotalQuantity(newValue);
                    notifyItemChanged(viewHolder.getAdapterPosition());
                    productList.set(position, product);
                    cartTable.put(product.getId(), product.getMetricPosition(), product);
                    itemChangedListener.onItemAdded(cartTable, newValue-oldValue);

                }
            }
        });
        viewHolder.clickView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(productList.get(viewHolder.getAdapterPosition()));
            }
        });
        return this.viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder mViewHolder, int position) {
        Item product = getItem(position);
        picasso.load(product.getImageUrl()).fit().into(viewHolder.productImage);
        String price = CurrencyUtils.getCurrencySymbol(product.getCurrency()) + product.getPrice().get(product.getMetricPosition());
        viewHolder.productPrice.setText(price);
        viewHolder.productName.setText(product.getName());
        viewHolder.productQuantity.setText(product.getQuantity().get(product.getMetricPosition()));
        viewHolder.productQuantity.setTypeface(FontUtils.getRegularTypeFace());
        viewHolder.productQuantity.setOnClickListener(dialogClickListener);
        if(product.getTotalQuantity() &gt; 0)
        {
            viewHolder.viewSwitcher.setDisplayedChild(1);
            viewHolder.numberButton.setNumber(String.valueOf(product.getTotalQuantity()),false);
        }
        else if(product.getStock() &gt; 0)
        {
            viewHolder.viewSwitcher.setDisplayedChild(0);
            viewHolder.cartAdd.setBackgroundColor(Color.WHITE);
            viewHolder.cartAdd.setTag(false);
            viewHolder.cartAdd.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_cart_add));
        }
        else {
            viewHolder.viewSwitcher.setDisplayedChild(0);
            viewHolder.cartAdd.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_cart_soldout));
        }

        removeButtonShadow(viewHolder.productQuantity);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return productList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        ImageView productImage,cartAdd;
        TextView productName;
        TextView productPrice;
        Button productQuantity;
        ElegantNumberButton numberButton;
        ViewSwitcher viewSwitcher;
        View clickView;
        public ViewHolder(View itemView) {
            super(itemView);
            this.clickView = itemView;
            productImage = (ImageView) itemView.findViewById(R.id.product_image);
            productName = (TextView) itemView.findViewById(R.id.product_name);
            productPrice = (TextView) itemView.findViewById(R.id.product_price);
            productQuantity = (Button) itemView.findViewById(R.id.product_quantity);
            cartAdd = (ImageView) itemView.findViewById(R.id.cart_add);
            numberButton = (ElegantNumberButton) itemView.findViewById(R.id.number_button);
            viewSwitcher = (ViewSwitcher) itemView.findViewById(R.id.view_switcher);
        }

    }

    private View.OnClickListener dialogClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            FragmentTransaction fragmentTransaction = ((Activity) context).getFragmentManager().beginTransaction();
            Fragment previousDialog = ((Activity) context).getFragmentManager().findFragmentByTag(StringConstants.DIALOG_TAG);
            if(previousDialog != null)
            {
                fragmentTransaction.remove(previousDialog);
            }
            fragmentTransaction.addToBackStack(null);
            QuantityDialogFragment mFragment = QuantityDialogFragment.newInstance(getItem(viewHolder.getAdapterPosition()),getItem(viewHolder.getAdapterPosition()).getMetricPosition());
            mFragment.setQuantityListener(new OnQuantityChosen() {
                @Override
                public void onSelectQuantity(int position) {
                    Item item = getItem(viewHolder.getAdapterPosition());
                    item.setMetricPosition(position);
                    item.setTotalQuantity(0);
                    productList.set(viewHolder.getAdapterPosition(),item);
                    notifyItemChanged(viewHolder.getAdapterPosition());
                }
            });
            mFragment.show(fragmentTransaction,StringConstants.DIALOG_TAG);
        }
    };

    private void removeButtonShadow(Button button)
    {
        if(Build.VERSION.SDK_INT &gt;= 21)
            button.setStateListAnimator(null);
    }

    public void setOnItemChangedListener(OnItemChanged onItemChangedListener)
    {
        this.itemChangedListener = onItemChangedListener;
    }


}
</code></pre>

<p>I am experiencing frame skips especially when I encounter the following lines,</p>

<pre><code>viewHolder.clickView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(product);
            }
        });
</code></pre>

<p>I could not figure out where the problem arises from. But once I click the recyclerview Item, I am having a visible and significant frameskip with the compiler throwing 300+ frame skips in the trace. Could anyone narrow it down and suggest some change ?</p>

<p><strong>Edit</strong></p>

<p>Here is my Eventbus Subscriber.</p>

<pre><code>@Subscribe(threadMode = ThreadMode.BACKGROUND)
    public void onProductClicked(Item product)
    {
        Fragment fragment = ProductLandingFragment.newInstance(product);
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
//        fragmentTransaction.hide(fragmentManager.findFragmentByTag(StringConstants.FRAGMENT_CATEGORIES_TAG));
        fragmentTransaction.replace(R.id.fragmentholder,fragment,StringConstants.FRAGMENT_PRODUCT_TAG);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    }
</code></pre>