-1

I am trying to call activity by clicking card view. The app is crashing when I click cardview:

Here is the code:

cardView.setOnClickListener(new View.OnClickListener() { 
   @Override 
   public void onClick(View v) { 
      context.startActivity(new Intent(context,Dummy.class));
   }
});

But if I put a toast message instead - it is working fine. What is wrong here?

SergGr
  • 23,570
  • 2
  • 30
  • 51

1 Answers1

0

Try removing context from context.startActivity();

cardView.setOnClickListener(new View.OnClickListener() { 
   @Override 
   public void onClick(View v) { 
      startActivity(new Intent(context,Dummy.class));
   }
});

If your outer class is some Activity subclass it is already a Context and it might be beter to use it to show another Activity.

SergGr
  • 23,570
  • 2
  • 30
  • 51