i am using facebook sdk 3.0 ,and i m following the tutorial https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ her is the code i am using
my code includes a button clicking on which it should show the facebook page to authenticate the user but on clicking the button it only shows the spinning bar and exits
package com.example.fblogin;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
private static final int SPLASH = 0;
private static final int SELECTION = 1;
private static final int FRAGMENT_COUNT = SELECTION +1;
private boolean isResumed = false;
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback =
new Session.StatusCallback() {
@Override
public void call(Session session,
SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
FragmentTransaction transaction = fm.beginTransaction();
for(int i = 0; i < fragments.length; i++) {
transaction.hide(fragments[i]);
}
transaction.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void showFragment(int fragmentIndex, boolean addToBackStack) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
for (int i = 0; i < fragments.length; i++) {
if (i == fragmentIndex) {
transaction.show(fragments[i]);
} else {
transaction.hide(fragments[i]);
}
}
if (addToBackStack) {
transaction.addToBackStack(null);
}
transaction.commit();
}
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
isResumed = true;
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
isResumed = false;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
// Only make changes if the activity is visible
if (isResumed) {
FragmentManager manager = getSupportFragmentManager();
// Get the number of entries in the back stack
int backStackSize = manager.getBackStackEntryCount();
// Clear the back stack
for (int i = 0; i < backStackSize; i++) {
manager.popBackStack();
}
if (state.isOpened()) {
// If the session state is open:
// Show the authenticated fragment
showFragment(SELECTION, false);
} else if (state.isClosed()) {
// If the session state is closed:
// Show the login fragment
showFragment(SPLASH, false);
}
}
}
@Override
protected void onResumeFragments() {
super.onResumeFragments();
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
// if the session is already open,
// try to show the selection fragment
showFragment(SELECTION, false);
} else {
// otherwise present the splash screen
// and ask the user to login.
showFragment(SPLASH, false);
}
}
}
here is the logcat data
04-08 15:43:05.164: D/dalvikvm(897): GC_CONCURRENT freed 106K, 8% free 2694K/2920K, paused 11ms+4ms, total 105ms
04-08 15:43:05.433: D/gralloc_goldfish(897): Emulator without GPU emulation detected.
04-08 15:43:12.383: D/dalvikvm(897): GC_FOR_ALLOC freed 145K, 9% free 2895K/3164K, paused 80ms, total 88ms
04-08 15:43:12.413: I/dalvikvm-heap(897): Grow heap (frag case) to 3.548MB for 635812-byte allocation
04-08 15:43:12.523: D/dalvikvm(897): GC_FOR_ALLOC freed 2K, 8% free 3513K/3788K, paused 104ms, total 104ms
04-08 15:43:12.683: D/dalvikvm(897): GC_CONCURRENT freed 4K, 8% free 3519K/3788K, paused 9ms+4ms, total 162ms
04-08 15:43:12.983: I/Choreographer(897): Skipped 431 frames! The application may be doing too much work on its main thread.
04-08 15:43:13.383: I/Choreographer(897): Skipped 51 frames! The application may be doing too much work on its main thread.
04-08 15:43:15.133: D/FacebookSDK.WebDialog(897): Webview loading URL: https://m.facebook.com/dialog/oauth?type=user_agent&redirect_uri=fbconnect%3A%2F%2Fsuccess&display=touch&client_id=153791708115302
04-08 15:43:15.343: D/dalvikvm(897): GC_CONCURRENT freed 127K, 7% free 3867K/4120K, paused 18ms+18ms, total 102ms
04-08 15:43:15.403: I/Choreographer(897): Skipped 70 frames! The application may be doing too much work on its main thread.
04-08 15:43:15.563: I/Choreographer(897): Skipped 34 frames! The application may be doing too much work on its main thread.
04-08 15:43:18.483: A/libc(897): Fatal signal 11 (SIGSEGV) at 0x00000120 (code=1), thread 914 (CookieSyncManag)
User contributions licensed under CC BY-SA 3.0