您好,登錄后才能下訂單哦!
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(),"注冊(cè)成功:" + user.getUsername() + "-" + user.getObjectId()
+ "-" + user.getCreatedAt() + "-"
+ user.getSessionToken() + ",是否驗(yàn)證:"
+ user.getEmailVerified());
2. 判斷登錄狀態(tài)工具
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 注冊(cè)成功后設(shè)置登錄狀態(tài)為true,再跳轉(zhuǎn)
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里面根據(jù)登錄狀態(tài)設(shè)置不同顯示界面
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.跳轉(zhuǎn)工具(基于判斷登錄狀態(tài))
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));
}
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。