[英]make own logout button & redirect after login
I made so I can login to Facebook by pressing the loginbutton. 我这样做是为了可以按登录按钮登录Facebook。 Just write in my user-name and password and it will log me in.
只要输入我的用户名和密码,它就会登录。
After that I have been logged in, it will take me back to the same Activity and with a blue Logout button. 登录后,它将带我回到同一活动,并带有蓝色的注销按钮。
Im going to build a navigator-drawer or actionbar, and THERE I will make an own logout button that logs me out from Facebook. 我将建立一个导航抽屉或操作栏,然后我将创建一个自己的注销按钮,该按钮将我从Facebook中注销。 In other words, I dont want the blue logout button.
换句话说,我不希望蓝色的注销按钮。
Also, where can I redirect to another Activity after logging in? 另外,登录后我可以在哪里重定向到另一个活动?
So to be clear: 因此要明确:
After logging in to Facebook, there will be no blue LogOut button, it will instead be a button in actionbar that is says logout and that button will log me out (how to, and what to delete in the code?) 登录到Facebook后,将没有蓝色的“注销”按钮,而是操作栏中的一个按钮,该按钮显示“注销”,并且该按钮将使我注销(如何以及在代码中删除什么?)。
After that I have logged in, I will redirect to a new Activity (how to..?) Here is my code: 登录后,我将重定向到新的活动(如何.. ??),这是我的代码:
public class SocialLoginFragment extends Fragment {
private static final String TAG = "MainFragment";
private UiLifecycleHelper uiHelper;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_social_login, container,
false);
LoginButton authButton = (LoginButton) view
.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("name", "user_birthday",
"friends_birthday"));
return view;
}
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
} }
And here is the other code: 这是其他代码:
public class SocialLoginActivity extends FragmentActivity {
private SocialLoginFragment socialLoginFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
socialLoginFragment = new SocialLoginFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, socialLoginFragment).commit();
} else {
// Or set the fragment from restored state info
socialLoginFragment = (SocialLoginFragment) getSupportFragmentManager()
.findFragmentById(android.R.id.content);
}
}
} }
EDIT : 编辑 :
I don't now if my problem/question was good written, will try again. 现在,如果我的问题/问题写得很好,我不会再尝试。
My Login to Facebook button are in the middle of my Activity, and thats fine. 我的登录Facebook按钮位于我的活动中间,这很好。 After that I login with the button, the button will change to LogOut.
之后,我使用按钮登录,该按钮将更改为LogOut。 The thing is that I will have an ActionBar or make my own button and put it in the Navigator-Drawer, so therefore, I dont need the blue LogOut button, I will delete it and put what LogOut button do in another button that I made.. (How do I delete the Logout button without delete the Login button, and how do I make a new button that will logout from Facebook)
问题是,我将拥有一个ActionBar或创建自己的按钮并将其放置在Navigator-Drawer中,因此,我不需要蓝色的LogOut按钮,我将其删除并将LogOut按钮的作用放在我制作的另一个按钮中..(如何删除“注销”按钮而不删除“登录”按钮,以及如何使新按钮从Facebook注销)
After that I logged in, I will come back to the same Activity, what I want to do is to send me to a new Activity, not the same Activity, in that way, the LogOut button will be gone? 登录后,我将返回相同的活动,我想要做的是将我发送到新的活动,而不是相同的活动,这样注销按钮会消失吗?
ANOTHER EDIT: 另一个编辑:
If I understand what you are trying to do, you don't need to delete the buttons, just hide them. 如果我了解您要执行的操作,则无需删除按钮,只需隐藏它们即可。
To hide or show buttons, do something like this: 要隐藏或显示按钮,请执行以下操作:
findViewById (R.id.login_button).setVisibility (View.GONE); // hides button
or 要么
button.setVisibility (View.VISIBLE);
When the state is changed and you verify if the session is opened, you can create an intent to call your activity. 更改状态并验证会话是否打开后,可以创建一个调用活动的意图。
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
Intent intent = new Intent(getActivity(), NewActivityYouMade.class);
startActivity(intent);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.