按下后出现空白屏幕

时间:2012-06-09 05:31:52

标签: android facebook-graph-api facebook-android-sdk

我希望我的应用程序使用fb登录(这是可选的)。所以首先我要启动我的基础活动,然后将fb活动作为子活动。我希望当用户按下后退按钮时,它应该返回其父活动。对于facebook活动,未设置contentview,它只是一个空白屏幕。我面临以下问题。

  1. 当fb活动启动时&我按回来,出现一个空白屏幕,可能(我不确定)是我没有设置的内容视图。我希望它能指导父母活动&不要这个空白的屏幕。
  2. 以下是代码:

    父级活动(启动器)

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

    任何帮助????

1 个答案:

答案 0 :(得分:0)

查看代码后几乎没有可能。由于FB很直接,但我不知道你为什么要这样做。根据你的代码......

  • 如果会话有效,您不会处理。因此,如果会话有效,请完成活动。
  • 您应该处理Listener中的所有事件。
  • 您不应在onActivityResult中创建新意图,请使用该函数中传递的意图。