I want to start a new activity in non-Activity class that implements a DialogListener
following is my code:
public class FacebookLoginDialog implements DialogListener {
@Override
public void onComplete(Bundle values) {
HomeActivity.showInLog(values.toString());
Intent i1 = new Intent (this, SearchActivity.class);
startActivity(i1);
}
@Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
@Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
}
}
I can't start the new activity using intent in onComplete
method, please help.
Thanks
This doesn't work because you need a Context
in order to start a new activity. You can reorganize your class into something like this:
public class FacebookLoginDialog implements DialogListener {
private final Context context;
public FacebookLoginDialog(Context context) {
this.context = context;
}
@Override
public void onComplete(Bundle values) {
HomeActivity.showInLog(values.toString());
Intent i1 = new Intent (context, SearchActivity.class);
context.startActivity(i1);
}
//Other methods...
}
Then it will work.
Pass context as constructor parameter and then try this
Intent i = new Intent(this, SearchActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With