0

我正在使用教程。我在 MainActivity 中通过 facebook 登录和注销,问题是如何在下一个(主页)活动中执行注销?对于 HomeActivity ,我自己创建(通过创建新活动)。

这是家庭活动的代码

package com.innoark.motivator;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

import com.facebook.Session;

public class Home extends Activity {

    Button button;
    MenuItem logout , writepost , send;

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

    }


    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        Session session = Session.getActiveSession();
        if (session != null && session.isOpened()) {
            if (menu.size() == 0) {
                writepost = menu.add(R.string.writepost);
                logout = menu.add(R.string.settings);

            }
            return true;
        } else {
            menu.clear();
            logout = null;
            writepost = null;
        }
    return true;
    }

//  @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.equals(logout)) {

            return true;
        }
        if (item.equals(writepost)){
            Intent intent = new Intent (this,MainActivity.class);
            startActivity(intent);
        }
        return true;
    }

}

提前致谢 :)

4

1 回答 1

0

这是注销的代码,您可以检查它............

    signoutbtn = (Button) findViewById(R.id.signout_btn);
    signoutbtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            SharedPreferences mSharedPreference =getSharedPreferences("SharedData",Context.MODE_PRIVATE);
            SharedPreferences.Editor mSaveState = mSharedPreference.edit();
            mSaveState.putBoolean("LoginSession", false);
            mSaveState.commit();
            Intent signout = new Intent(HotTaxiTabActivity.this,Login.class);
            signout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(signout);
        }
    });




 if (item.equals(logout)) 
  {

        SharedPreferences mSharedPreference =getSharedPreferences("SharedData",Context.MODE_PRIVATE);
            SharedPreferences.Editor mSaveState = mSharedPreference.edit();
            mSaveState.putBoolean("LoginSession", false);
            mSaveState.commit();
            Intent signout = new Intent(HotTaxiTabActivity.this,Login.class);
            signout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(signout);

    }
     return true;
于 2013-04-12T03:35:05.777 回答