2013-07-07 69 views
0

我想使用Facebook的Android SDK的官方教程here中给出的相同的代码。我还设法制作了教程应用程序。但是,现在我需要在我的另一个应用程序中完全相似的代码。然而,这一次,Eclipse说,代码中给出的onResumeFragments()方法不能被覆盖,如果我注释掉@Override表示法和super.onResumeFragments(),并尝试运行该项目,我的应用程序显示空白活动。 这里是代码我跑..onResumeFragments不能被覆盖?

package com.gotechno.technovanza13; 

import com.facebook.Session; 
import com.facebook.SessionState; 
import com.facebook.UiLifecycleHelper; 

import android.content.Intent; 
import android.os.Bundle; 
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 FbLoginActivity extends FragmentActivity { 

    private static final int SPLASH = 0; 
    private static final int SELECTION = 1; 
    private static final int FRAGMENT_COUNT = SELECTION +1; 
    private Fragment[] fragments = new Fragment[FRAGMENT_COUNT]; 
    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); 
     } 
    }; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     uiHelper = new UiLifecycleHelper(this, callback); 
     uiHelper.onCreate(savedInstanceState); 
     setContentView(R.layout.fb_fragment_container); 

     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(); 
    } 

    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(); 
    } 

    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 <--- here is where I commented out to remove error 
    protected void onResumeFragments() { 
     //super.onResumeFragments(); <--- here is where I commented out to remove error 
     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 person to login. 
      showFragment(SPLASH, false); 
     } 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     isResumed = true; 
    } 

    @Override 
    public void onPause() { 
     super.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 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; 
    } 

}  

请告诉如何正确地重写方法并加载片段活动...谢谢:)

回答

2

我想这是因为你试图使用该库的旧版本。如果你看看history,它只能在4.1.1上添加。

+0

谢谢,任何方式来通过它,然后呢? – tigerden

0

我已经从项目的lib中删除了'android-support-v4.jar',因为我遇到了JAR不匹配问题。加入该文件再次解决了我的问题.. :)