title: java.lang.RuntimeException: Adding window failed please give me solution
body: <p>from two days i has been find the solution for this exception please anybody can give solution for this problem  . in this current activity we used the recyclerview 1000+ items .</p>
  
  <p>java.lang.RuntimeException: Adding window failed 
  Caused by: android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died</p>
  
  <p>this is  constructor of recycler Adapter class</p>
  
  <pre><code> Recycler_Adapter_one_line(Context context, Activity activity, FragmentManager fragmentManager,SQLiteDatabase database,View view){
          this.context=context;
          dataBinder.quetion_list();
          this.activity=activity;
          this.fragmentManager=fragmentManager;
          this.database=database;
          this.view=view;
      }
  </code></pre>
  
  <p>given code is my OnCreateViewHolder method </p>
  
  <pre><code> @NonNull
      @Override
      public View_holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          LayoutInflater l=LayoutInflater.from(context);
        View v=  l.inflate(R.layout.recycler_adapter_one_line_inflater,parent,false);
          final View_holder holder=new View_holder(v);
          final ImageView img_download=v.findViewById(R.id.download);
          final ImageView img_favourite=v.findViewById(R.id.img_favourite);
          img_download.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  dataBinder.getAnim(context,img_download);
                  Answer_Bottom_sheet sheet=new Answer_Bottom_sheet(holder.getAdapterPosition(),dataBinder);
                  sheet.show(fragmentManager,"ajay");
              }
          });
          img_favourite.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Snackbar.make(view,"Quetion added to favorite...",Snackbar.LENGTH_LONG).setAction("Check out", new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                            Intent i=new Intent(context,Favorite_quetion_activity.class);
                            context.startActivity(i);
                      }
                  }).show();
                  dataBinder.getAnim(context,img_favourite);
                  try {
                      ArrayList&lt;Integer&gt; arr=new ArrayList&lt;Integer&gt;();
                      Cursor cursor =database.query("FAVOURITE_TABLE",null,null,null,null,null,null);
                      while (cursor.moveToNext()){
                          arr.add(cursor.getInt(0));
                      }
                      if(arr.isEmpty()){
                          ContentValues values=new ContentValues();
                          values.put("val",holder.getAdapterPosition());
                          database.insert("FAVOURITE_TABLE",null,values);
                          arr.clear();
                      }
                      if(!arr.isEmpty()) {
                        if(!arr.contains(holder.getAdapterPosition())){
                            ContentValues values=new ContentValues();
                            values.put("val",holder.getAdapterPosition());
                            database.insert("FAVOURITE_TABLE",null,values);
                            arr.clear();
                        }
                      }
                  }
                  catch (Exception e){
                           Toast.makeText(context,""+e,Toast.LENGTH_LONG).show();
                  }
              }
          });
          return holder;
      }
  </code></pre>
  
  <p>following code of OnCreateViewHolder method </p>
  
  <pre><code> @Override
      public void onBindViewHolder(@NonNull View_holder holder, int position) {
          try {
              ArrayList&lt;Integer&gt; arr = new ArrayList&lt;Integer&gt;();
              Cursor cursor = database.query("FAVOURITE_TABLE", null, null, null, null, null, null);
              while (cursor.moveToNext()) {
                  arr.add(cursor.getInt(0));
              }
              if (arr.contains(position)) {
                  holder.img_favourite.setImageResource(R.drawable.ic_favorite_white_24dp);
              } else if (!arr.contains(position)) {
                  holder.img_favourite.setImageResource(R.drawable.ic_favorite_border_white_24dp);
              }
              holder.txt_sr.setText(Integer.toString(position + 1));
              holder.txt_quetion.setText(dataBinder.arr_quaetion_list.get(position));
          }
          catch (Exception e){
              Toast.makeText(context,""+e,Toast.LENGTH_LONG).show();
          }
      }
  </code></pre>
  
  <p>following code of subclass of ViewHolder </p>
  
  <pre><code>class View_holder extends RecyclerView.ViewHolder {
           TextView txt_sr,txt_quetion;
           CardView cardView;
           ImageView img_favourite;
          public View_holder(@NonNull View
                                     itemView) {
              super(itemView);
              try{
              txt_sr=itemView.findViewById(R.id.txt_sr);
              txt_quetion=itemView.findViewById(R.id.txt_quetion);
              cardView=itemView.findViewById(R.id.cardView);
              img_favourite=itemView.findViewById(R.id.img_favourite);
              }
              catch (Exception e){
                  Toast.makeText(context,""+e,Toast.LENGTH_LONG).show();
              }
          }
  </code></pre>
  
  <p>logcat showing me following Exception</p>
  
  <p>exception no:-1 </p>
  
  <pre><code>java.lang.IllegalArgumentException
      at android.view.Surface.nativeLockCanvas(Native Method)
      at android.view.Surface.lockCanvas(Surface.java:321)
      at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:3109)
      at android.view.ViewRootImpl.draw(ViewRootImpl.java:3083)
      at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2851)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2404)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6886)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1029)
      at android.view.Choreographer.doCallbacks(Choreographer.java:841)
      at android.view.Choreographer.doFrame(Choreographer.java:772)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1015)
      at android.os.Handler.handleCallback(Handler.java:794)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:176)
      at android.app.ActivityThread.main(ActivityThread.java:6651)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
  </code></pre>
  
  <p>Exception no :- 2</p>
  
  <pre><code> java.lang.RuntimeException: Adding window failed
                      at android.view.ViewRootImpl.setView(ViewRootImpl.java:769)
                      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
                      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
                      at android.widget.Toast$TN.handleShow(Toast.java:500)
                      at android.widget.Toast$TN$1.handleMessage(Toast.java:404)
                      at android.os.Handler.dispatchMessage(Handler.java:106)
                      at android.os.Looper.loop(Looper.java:176)
                      at android.app.ActivityThread.main(ActivityThread.java:6651)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
                   Caused by: android.os.DeadObjectException: Transaction failed on small parcel; remote process probably died
                      at android.os.BinderProxy.transactNative(Native Method)
                      at android.os.BinderProxy.transact(Binder.java:776)
                      at android.view.IWindowSession$Stub$Proxy.addToDisplay(IWindowSession.java:801)
                      at android.view.ViewRootImpl.setView(ViewRootImpl.java:757)
                      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
  
                      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94) 
                      at android.widget.Toast$TN.handleShow(Toast.java:500) 
                      at android.widget.Toast$TN$1.handleMessage(Toast.java:404) 
                      at android.os.Handler.dispatchMessage(Handler.java:106) 
                      at android.os.Looper.loop(Looper.java:176) 
                      at android.app.ActivityThread.main(ActivityThread.java:6651) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
  
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
  </code></pre>