facebook login not working in my app its closing itself when logged in?

Question

facebook login not working in my app its closing itself when logged in when i tried to put the onActivityresult in fragment activity it doesnt worked when i put it in to mainactivity the app closes itself why ? this is my fragment activity

enter code here
package com.example.admin.youfame;
import android.content.Intent;
import android.content.pm.PackageInstaller; 
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger; 
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;




    public class PostFragment extends Fragment {
   CallbackManager callbackManager;
   LoginButton loginButton;
  public PostFragment() {
    // Required empty public constructor
}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    FacebookSdk.sdkInitialize(this.getContext());
   AppEventsLogger.activateApp(this.getContext());

    View view = inflater.inflate(R.layout.fragment_post, container, false);
    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) view.findViewById(R.id.login_button);
    final TextView textView =  (TextView)view.findViewById(R.id.textView9);
    loginButton.setReadPermissions("email");
    loginButton.setFragment(this);

    //loginButton.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            textView.setText("login success/n");
        }
        @Override
        public void onCancel() {
            textView.setText("canceled");
        }
        @Override
        public void onError(FacebookException exception) {
            textView.setText("Errorr");
        }
    });
    return inflater.inflate(R.layout.fragment_post, container, false);
}


 /*   public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);

    }*/
}

this is my main activity

 package com.example.admin.youfame;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.facebook.CallbackManager;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

 public class MainActivity extends AppCompatActivity {

 private SectionsPagerAdapter mSectionsPagerAdapter;
 private ViewPager mViewPager;
 CallbackManager callbackManager;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-2991702481825090~2141609165");
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest request = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)        // All emulators
            .addTestDevice("658F3783B85CC8CA35A2B54A49AA11D9")  // An   example device ID
            .build();

    mAdView.loadAd(request);

    //658F3783B85CC8CA35A2B54A49AA11D9


    mSectionsPagerAdapter = new    SectionsPagerAdapter(getSupportFragmentManager());


    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);


  }
  public void onActivityResult(int requestCode, int resultCode, Intent   data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);

 }
/*  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is    present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}
*/
/*  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
 }*/
  public class SectionsPagerAdapter extends FragmentStatePagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {

            case 0:
                return new VideoFragment();
           case 1:
                return new PostFragment();

        }
        return null;
    }

    @Override
    public int getCount() {

        return 2;
    }


    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return getString(R.string.name_fragment);
            case 1:
                return getString(R.string.name_fragment2);


        }
        return null;

    }

}
}

Show source
| java   | facebook   | android   | android-fragments   2017-01-07 12:01 0 Answers

Answers to facebook login not working in my app its closing itself when logged in? ( 0 )

Leave a reply to - facebook login not working in my app its closing itself when logged in?

◀ Go back