Search code examples
androidandroid-intentandroid-activityonclickandroid-context

how to start activity using context.startActivity(intent);...?


my app crashes when i click and an error log appears directing to the line mentioned below and it is also shows that you have to declare RecyclerAdapterNew into manifest file but no need bcz i haven't extended to AppCompat

public void onClick(View view) {


        tableData = Integer.parseInt(table.getText().toString());

        Context context = view.getContext();
        Intent intent = new Intent(context, RecyclerAdapterNew.class);

        intent.putExtra("transfer", tableData);

        context.startActivity(intent);//error in this line
    }

Solution

  • Try with this:

    ((Activity)context).startActivity(intent);