This is my code for first page and when I want to start an Activity I have this error:
Cannot resolve constructor 'Intent(com.example.loginpage.contact,java.lang.Class)'
public class contact extends AsyncTask<String,Void,String>{
Context context;
contact (Context ctx){
context = ctx;
}
protected void onPostExecute(String result) {
alertDialog.setMessage(result);
if (result.equals("Wrong email or password.")) {
} else
{
context.startActivity( new Intent(contact.this,mainpage.class));
}
alertDialog.show();
}
}
I want open this activity:
public class mainpage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainpage);
String username = getIntent().getStringExtra("Username");
TextView tv = (TextView)findViewById(R.id.username);
tv.setText(username);
}
}
You are trying to start a new Activity
from outside of a Context
. When you say contact.this
in the line:
startActivity( new Intent(contact.this,mainpage.class));
you are referring to an AsyncTask
as that's what contact
extends. You should pass in a Context
there instead. You can do that by passing Context
into your class contact
constructor.
Once you have Context
passed into the contact
you replace contact.this
with:
context.startActivity(new Intent(context, mainpage.class));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments