简体   繁体   English

为Android构建Facebook登录应用

[英]Constructing a Facebook login app for android

I'm using this link for facebook integration with android app. 我正在使用此链接与Android应用程序进行Facebook集成。
That link says, 该链接说,

In main activity, make the activity subclass FragmentActivity instead of Activity:  

Here is my code: 这是我的代码:

import com.facebook.AppEventsLogger;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
      super.onResume();

      // Logs 'install' and 'app activate' App Events.
      AppEventsLogger.activateApp(this);
    }

    @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;
    }

    @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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onPause() {
      super.onPause();

      // Logs 'app deactivate' App Event.
      AppEventsLogger.deactivateApp(this);
    }
}

When I change public class MainActivity extends Activity { to public class MainActivity extends FragmentActivity { , then I get the following errors: 当我将public class MainActivity extends Activity {更改为public class MainActivity extends FragmentActivity { ,则出现以下错误:

FragmentActivity cannot be resolved to a type   MainActivity.java   /Login/src/edu/cheerz/login line 11 Java Problem
FragmentActivity cannot be resolved to a type   MainActivity.java   /Login/src/edu/cheerz/login line 15 Java Problem
FragmentActivity cannot be resolved to a type   MainActivity.java   /Login/src/edu/cheerz/login line 21 Java Problem
FragmentActivity cannot be resolved to a type   MainActivity.java   /Login/src/edu/cheerz/login line 43 Java Problem
FragmentActivity cannot be resolved to a type   MainActivity.java   /Login/src/edu/cheerz/login line 48 Java Problem
R cannot be resolved to a variable  MainActivity.java   /Facebook/src/com/cheerz/facebook   line 14 Java Problem
R cannot be resolved to a variable  MainActivity.java   /Facebook/src/com/cheerz/facebook   line 21 Java Problem
R cannot be resolved to a variable  MainActivity.java   /Facebook/src/com/cheerz/facebook   line 31 Java Problem
R cannot be resolved to a variable  MainActivityA.java  /Trial/src/com/cheerz/trial line 19 Java Problem
R cannot be resolved to a variable  MainActivityA.java  /Trial/src/com/cheerz/trial line 21 Java Problem
R cannot be resolved to a variable  MainActivityA.java  /Trial/src/com/cheerz/trial line 37 Java Problem
R cannot be resolved to a variable  MainActivityB.java  /Trial/src/com/cheerz/trial line 16 Java Problem
The method activateApp(Context) in the type AppEventsLogger is not applicable for the arguments (MainActivity)  MainActivity.java   /Login/src/edu/cheerz/login line 24 Java Problem
The method deactivateApp(Context) in the type AppEventsLogger is not applicable for the arguments (MainActivity)    MainActivity.java   /Login/src/edu/cheerz/login line 51 Java Problem
The method getMenuInflater() is undefined for the type MainActivity MainActivity.java   /Login/src/edu/cheerz/login line 30 Java Problem
The method onCreate(Bundle) of type MainActivity must override or implement a supertype method  MainActivity.java   /Login/src/edu/cheerz/login line 14 Java Problem
The method onCreateOptionsMenu(Menu) of type MainActivity must override or implement a supertype method MainActivity.java   /Login/src/edu/cheerz/login line 28 Java Problem
The method onCreateView(LayoutInflater, ViewGroup, Bundle) of type MainActivityA must override or implement a supertype method  MainActivityA.java  /Trial/src/com/cheerz/trial line 35 Java Problem
The method onCreateView(LayoutInflater, ViewGroup, Bundle) of type MainActivityB must override or implement a supertype method  MainActivityB.java  /Trial/src/com/cheerz/trial line 13 Java Problem
The method onCreateView(String, Context, AttributeSet) in the type Activity is not applicable for the arguments (LayoutInflater, ViewGroup, Bundle) MainActivityB.java  /Trial/src/com/cheerz/trial line 15 Java Problem
The method onOptionsItemSelected(MenuItem) of type MainActivity must override or implement a supertype method   MainActivity.java   /Login/src/edu/cheerz/login line 35 Java Problem
The method onPause() of type MainActivity must override or implement a supertype method MainActivity.java   /Login/src/edu/cheerz/login line 47 Java Problem
The method onResume() of type MainActivity must override or implement a supertype method    MainActivity.java   /Login/src/edu/cheerz/login line 20 Java Problem
The method setContentView(int) is undefined for the type MainActivity   MainActivity.java   /Login/src/edu/cheerz/login line 16 Java Problem

How can I fix these errors? 如何解决这些错误? This is an experiment and would result in an awesome app ;) 这是一个实验,将产生一个很棒的应用程序;)

I solved it. 我解决了 I was getting confused between android-support-v4 and android-support-v7 . 我对android-support-v4android-support-v7感到困惑。 I was using android-support-v7 and found that it doesn't support Fragment. 我使用的是android-support-v7 ,发现它不支持Fragment。 So I used v4 and it worked 所以我用了v4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM