我正在使用this教程。我在MainActivity中通过facebook登录和注销,问题是如何在下一个(Home)活动中执行注销?对于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;
}
}
提前致谢:)
答案 0 :(得分:0)
以下是Logout的代码,您可以查看它..............
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;