zoukankan      html  css  js  c++  java
  • android项目杂记

    1、自动登录,在SdCrmApplication 代码中,

     String username = String.valueOf(SpUtils.get(this, SharePrefUtil.KEY.USER_NAME, ""));
                String password = String.valueOf(SpUtils.get(this, SharePrefUtil.KEY.USER_PASSWORD, ""));
    

     2、记录用户信息,在登录后LoginActivity

     protected void saveUserInfor(Users users, String password) {
            app.setUsers(users);
            try {
                password= AesUtil.encrypt(password,JxConf.AESKEY);
                SpUtils.put(SharePrefUtil.KEY.USER_PASSWORD, password);
                SpUtils.put(SharePrefUtil.KEY.USER_NAME, users.getUsername());
            } catch (Exception e) {
                e.printStackTrace();
            }
    
    
        }
    

     3、退出登录 UserInformationActivity

    	build.setPositiveButton("确定", new DialogInterface.OnClickListener() {
    
    				@Override
    				public void onClick(DialogInterface dialog, int which) {
    					// 右盟分析工具
    				//	MobclickAgent.onEvent(ct, JxConf.C_MYCOFFERS_PERSONALINFORMATION_DROPOUT);
    					removePushTag();
    					app.setUsers(null);
    					app.setUserInfo(null);
    
    					SpUtils.remove(ct,SharePrefUtil.KEY.USER_NAME);
    
    					SharePrefUtil.saveLong(ct, SharePrefUtil.KEY.LAST_UID, 0);
    					AppManager appManager = AppManager.getAppManager();
    					MainActivity activity = (MainActivity) appManager.indexOfActivity(0);
    					activity.getHomeFragment().settingMessage(0);
    					// 通知服务器登出
    					if (userService == null) {
    						userService = new UserService(ct);
    					}
    					userService.logout(users.getUsername(),new TextHttpResponseHandler(){
    						@Override
    						public void onFailure(int statusCode, Header[] headers,
    								String responseBody, Throwable error) {
    							super.onFailure(statusCode, headers, responseBody,
    									error);
    							setResult(RESULT_OK);
    							finish();
    						}
    
    						@Override
    						public void onSuccess(int statusCode, Header[] headers,
    								String responseBody) {
    							super.onSuccess(statusCode, headers, responseBody);
    							setResult(RESULT_OK);
    							finish();
    						}
    					});
    					activity.remoteGetAccessToken();
    					activity.getHomeFragment().selectPageView(R.id.rb_home);
    				}
    			});
    

     4、首次使用自动登录的地方MainActivity

    @Override
        protected void onResume() {
            Fragment fragment = getSupportFragmentManager().findFragmentByTag(
                    curTag);
            if (fragment != null) {
                fragment.onResume();
            }
            super.onResume();
            // resumeStatus = isAppOnForeground();
    
            if (app.getUsers() != null && app.getUsers().getUsername()!="") {
                if (stopStatus == true && isActive == false) {
    
                    boolean switcher = SharePrefUtil.getBoolean(ct,
                            SharePrefUtil.KEY.SWITCH_GESTURE, false);
                    if (switcher == true) {
                        isActive = true;// app 从后台唤醒,进入前台
                        stopStatus = true;
                        long intoTime=SharePrefUtil.getLong(ct,SharePrefUtil.KEY.OUT_TIME,0);
                        if(System.currentTimeMillis()-intoTime>= Constants.INTOTIMELOCKED) {
                            // 暂时不提供锁频界面
                           /* Intent intent = new Intent(this, LockActivity.class);
                            startActivity(intent);*/
                        }
                    }
    
                }
            }
    
    
        }
    
  • 相关阅读:
    分析ARP攻击与欺骗
    IP数据包结构
    OSI 7层模型
    PKI
    求一个字符串所有的子序列:非递归和递归算法
    空当接龙求解:java版广度优先
    mysql 解决奇葩问题续篇。
    mysql 的一个奇葩问题
    symfony 之 admin 征途二 数据库相关
    symfony 之 admin 征途一 试运行
  • 原文地址:https://www.cnblogs.com/hoge/p/6286645.html
Copyright © 2011-2022 走看看