Skip to content Skip to sidebar Skip to footer

Cannot Resolve Method Startactivity()

I'm new to the android development and having a bit of a problem changing activities. I am trying to change activities from within a method but I am getting the error cannot resolv

Solution 1:

You should use the context of your adapter:

publicvoidopen301(View view){
  Intent openThree = newIntent(context,ThreeZeroOne.class);
  context.startActivity(openThree);
}

Solution 2:

To start a new activity you will need a context to start from, and your current activity "BaseAdapter" is not a Context, luckly every view has a Context, so you can do like this:

publicvoidopen301(View view){
    Intent openThree = newIntent(view.getContext(), ThreeZeroOne.class);
    view.getContext().startActivity(openThree);
}

Solution 3:

First you should get your Context:

private Context context;

publicCustomAdapter(Context context){
    this.context = context;
}

And then:

context.startActivity(openThree);

Solution 4:

you can also pass messages

 Intent i = newIntent( getContext(),Chat.class);
            i.putExtra("id",user.id);
            i.putExtra("name",user.name);
            getContext().startActivity(i);

Post a Comment for "Cannot Resolve Method Startactivity()"