您好,登錄后才能下訂單哦!
Toast工具
public class MyToast {
public static void makeText(Context context, CharSequence text){
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
}
1.1 Toast工具
final User user = new User(username, password,"138604167");
user.signUp(getActivity(), new SaveListener() {
public void onSuccess() {
MyToast.makeText(getActivity(),"注冊成功:" + user.getUsername() + "-" + user.getObjectId()
+ "-" + user.getCreatedAt() + "-"
+ user.getSessionToken() + ",是否驗證:"
+ user.getEmailVerified());
2. 判斷登錄狀態工具
private static LoginStatus mInstance = new LoginStatus();
private boolean hasLogin;
private LoginStatus(){}
public static LoginStatus getInstance(){
return mInstance;
}
public boolean hasLogin() {
return hasLogin;
}
public void setHasLogin(boolean hasLogin) {
this.hasLogin = hasLogin;
}
}
2.1 注冊成功后設置登錄狀態為true,再跳轉
myUser = BmobUser.getCurrentUser(getActivity(), com.chencheng.model.User.class);
Log.e("life","本地用戶信息:objectId = " + myUser.getObjectId() + ",name = " + myUser.getUsername()
);
LoginStatus.getInstance().setHasLogin(true);
Intent intent = new Intent(getActivity(),
MainActivity.class);
intent.putExtra("user", myUser);
intent.putExtra("flag", "hasLogin");
startActivity(intent);
2.2 MainActivity中接受Intent值,如果是登陸成功,直接條狀到MineFragment
Intent intent=getIntent();
flag = intent.getStringExtra("flag");
if(flag!=null){
Log.e("MainIntent", flag);
if(flag.equals("hasLogin")){
mTabHost.setCurrentTab(2);
}
}
2.3 MineFragment里面根據登錄狀態設置不同顯示界面
if (LoginStatus.getInstance().hasLogin()){
com.chencheng.model.User myUser = BmobUser.getCurrentUser(getActivity(), com.chencheng.model.User.class);
TextView username=(TextView)mLayout.findViewById(R.id.username);
username.setText(myUser.getUsername());
mLayout.findViewById(R.id.has_not_login_container).setVisibility(View.GONE);
mLayout.findViewById(R.id.logined_container).setVisibility(View.VISIBLE);
}else{
mLayout.findViewById(R.id.has_not_login_container).setVisibility(View.VISIBLE);
mLayout.findViewById(R.id.logined_container).setVisibility(View.GONE);
}
3.跳轉工具(基于判斷登錄狀態)
public class UnLoginUtils {
public static void startActivity(Context context, Class class1){
if (LoginStatus.getInstance().hasLogin()){
context.startActivity(new Intent(context, class1));
}else{
context.startActivity(new Intent(context, LoginActivity.class));
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。