2012-06-09 93 views
0

我希望我的應用程序使用fb登錄(這是可選的)。所以首先我要啓動我的基本活動,然後將fb活動作爲兒童活動。我希望當用戶按下後退按鈕時,它應該返回到其父活動。對於facebook活動,contentview未設置,它只是一個空白屏幕。我正面臨以下問題。向後按時的空白屏幕

  1. 當FB活動啓動&我壓回,一個空白的屏幕顯示了這可能(我不知道)是我沒設置的內容視圖。我希望它能指向父母活動&而不是這個空白屏幕。

以下是代碼:

父活動(啓動)

public class AccountSettingsActivity extends Activity { 
    /** Called when the activity is first created. */ 
     Button registerButton; 
     Button fbButton; 

     AccountSettingsActivity ob ; 
     final Context cont = this; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.account); 
     Log.i ("Location_settings", "In Account Settings Class"); 

     registerButton = (Button)this.findViewById(R.id.registerbutton); 
     fbButton = (Button)this.findViewById(R.id.fbbutton); 

     registerButton.setVisibility(1); 

     //Toast.makeText(cont, "In Accounts Settings", Toast.LENGTH_LONG); 


     fbButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) {    
       Log.i("Account-Settings","fb Button clicked"); 
       Intent fb = new Intent(AccountSettingsActivity.this,facebookMain.class); 
       fb.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
       startActivityForResult(fb,0); 

      } 
     }); 

     registerButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) {    
       Log.i("Account-Settings","Register Button clicked"); 
       ProgressDialog dialog = ProgressDialog.show(AccountSettingsActivity.this, "Syncing with server", "Please wait...", true); 
       new initialsync(dialog).execute("");    

      } 
     }); 

     fbButton.performClick(); 

    } 

} 

兒童活動(臉譜)

public class facebookMain extends Activity { 

    String abc; 
    Facebook facebook = new Facebook("1234567890"); 
    private SharedPreferences mPrefs; 
     private Bundle parameters; 
     facebookMain ob; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     /* 
     * Get existing access_token if any 
     */ 


     mPrefs = getPreferences(MODE_PRIVATE); 
     String access_token = mPrefs.getString("access_token", null); 
     long expires = mPrefs.getLong("access_expires", 0); 
     if(access_token != null) { 
      facebook.setAccessToken(access_token); 
     } 
     if(expires != 0) { 
      facebook.setAccessExpires(expires); 
     } 

     /* 
     * Only call authorize if the access_token has expired. 
     */ 
     if(!facebook.isSessionValid()) { 

      facebook.authorize(this, new String[] { "read_friendlists", "read_mailbox", "email" }, new DialogListener() { 
       @Override 
       public void onComplete(Bundle values) { 
        SharedPreferences.Editor editor = mPrefs.edit(); 
        editor.putString("access_token", facebook.getAccessToken()); 

        abc = facebook.getAccessToken(); 


        editor.putLong("access_expires", facebook.getAccessExpires()); 
        editor.commit(); 

        Intent intent=new Intent();  
        intent.putExtra("access token",abc); 
        setResult(RESULT_OK, intent); 
        finish(); 
       } 

       @Override 
       public void onFacebookError(FacebookError error) {} 


       @Override 
       public void onCancel() { 
       finish(); 
       } 

       @Override 
       public void onError(DialogError e) { 
         // TODO Auto-generated method stub 

       } 
      }); 
     } 

     if(facebook.isSessionValid()) 
     { 
      SharedPreferences shared = mPrefs; 

      abc = shared.getString("access_token", ""); 

      Intent intent=new Intent();  
      intent.putExtra("access_token",abc); 
      setResult(RESULT_OK, intent); 
      Toast.makeText(ob,"facebook session valid", Toast.LENGTH_SHORT); 
      finish(); 
     } 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 

     facebook.authorizeCallback(requestCode, resultCode, data); 

     AppLog.logger("facebookmain, Back key pressed"); 
        Intent intent=new Intent();  
        intent.putExtra("abc",abc); 
        setResult(RESULT_OK, intent); 
        finish(); 
    } 
} 

任何幫助????

回答

0

查看您的代碼後幾乎沒有可能性。由於FB非常直接,但我不知道你爲什麼這樣做。根據您的代碼...

  • 如果會話有效,則不處理。因此,如果會話有效,請完成活動。
  • 您應該處理Listener中的所有事件。
  • 您不應在onActivityResult中創建新的意圖,請使用在該函數中傳遞的意圖。
+0

雅我沒有處理,如果會議是有效的。糾正了這一點。現在只有第一個疑問。如果用戶不想登錄並在那個時候再次按下,則顯示空白屏幕。而且他必須再次回去參加家長活動。請幫助dis也... –

+0

好吧,現在當用戶按下後退按鈕,您將在facebookMain活動中的「onResume()」上獲得流量。這就是你堅持使用黑屏的原因。我有與ImageCrop相同的概率,通過使用普通的類並傳遞給該類的活動解決了我的問題。所以這不會是一箇中間活動。 – Samdrain

+0

所以將不得不添加「onResume()」與「完成()」在其中? –