I have created a class which extends Gallery. There is no onCreate() method in super Class, and I’m unable to run my intent.
This is my sample code:
this.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent intent = new Intent(v.getContext(), ClassName.class);
startActivity(intent);
}}
The following attempt also failed to work:
Intent intent = new Intent(ThisClassName.this, ClassName.class);
startActivity(intent);
Any advice would be greatly appreciated 🙂
Actually,
startActivity();is the method of Activity class, To run this method you have toContext of ActivityorReference of Activity, You can not run this method in other class as outside of Activity scope without having Activity reference for it.Try,
or
Here mContext is reference of your Activity class.