I want to start a new activity when Facebook login completes that happens in a DialogListener. Login done successfully No error comes but activity doesn’t start. If you require logcat I can email you.
Following is my code.
Here is My HomeActivity
package com.example.faceb;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.Facebook;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class HomeActivity extends Activity implements OnClickListener{
private static final String TAG = "Facebook";
private Button mLogin, mLogout, mShare;
private Facebook facebook;
private AsyncFacebookRunner abRunner;
public boolean flag;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_home);
facebook = new Facebook("479652662068145");
abRunner = new AsyncFacebookRunner(facebook);
mLogin= (Button) findViewById(R.id.Login);
mLogout= (Button) findViewById(R.id.Logout);
mLogin.setOnClickListener(this);
mLogout.setOnClickListener(this);
}
@Override
public void onClick(View v){
int id = v.getId();
switch(id){
case R.id.Login:
FacebookLoginDialog login = new FacebookLoginDialog(this);
facebook.authorize(this, login);
if (func()==true)
{
Intent i = new Intent(this, SearchActivity.class);
startActivity(i);
}
break;
case R.id.Logout:
FacebookLogoutRequest logout = new FacebookLogoutRequest(this);
abRunner.logout(this, logout);
Toast toast = Toast.makeText(this, "You Are Logged Out", Toast.LENGTH_SHORT);
toast.show();
break;
default:
break;
}
}
public static boolean func() {
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_home, menu);
return true;
}
}
And Following my FacebookLoginDialog Class
public class FacebookLoginDialog implements DialogListener{
@Override
public void onComplete(Bundle values) {
HomeActivity.func();
}
@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
}
}
This dialog starts on a button click which is in my HomeActivity. Please help I searched a lot and tried but unable to solve this issue.
I think instead of starting the dialog on button click, u can start the activity, which u want to start after login. Then call the dialog inside the
onCreate()of the new activity. So that u can just close the dialog inonComplete()and automatically the new screen will appear. Just keep a flag in the activity and set it to true only when the login succeeds. So that u can finish the new activity if the flag is false after the dialog get closed.