页面跳转前对ToKen判断

public class GetMyWalletInfo { private Context context; private String action; public GetMyWalletInfo(Context context, String action) { this.context = context; this.action = action; } /*public GetMyWalletInfo(Context context) { this.context = context; }*/ public void getMyWallet() { if (new GetSharePerfence(context).getToken().equals("")) { Toast.makeText(context, "请先登录", Toast.LENGTH_LONG).show(); Intent intent = new Intent(context, LoginActivity.class); intent.putExtra("action",action); context.startActivity(intent); } else { RequestParams parmas = new RequestParams(Config.WALLETURL); parmas.addHeader("token", new GetSharePerfence(context).getToken()); x.http().get(parmas, new MyCallBack() { @Override public void onSuccess(String result) { Gson gson = new Gson(); ErrorMsg errorMsg = gson.fromJson(result, ErrorMsg.class); if (errorMsg.getErrorCode() == 300) {//错误码未300表示token过期 Toast.makeText(context, "已过期,请重新登录", Toast.LENGTH_LONG).show(); Intent intent = new Intent(context, LoginActivity.class); intent.putExtra("action",action); context.startActivity(intent); } else { Intent intent =new Intent(); intent.setAction(action); context.startActivity(intent); } super.onSuccess(result); } }); } } } -------------------------------------------- 点击前的token判断 @Override public void onClick(View view) { switch (view.getId()) { case R.id.helper: new GetMyWalletInfo(getContext(), "com.carinsurance").getMyWallet(); // getUserInfo(); //实名认证 break; case R.id.rl_wallet: new GetMyWalletInfo(getContext(), "com.home").getMyWallet(); break; case R.id.rl_task: new GetMyWalletInfo(getContext(), "com.insurance").getMyWallet(); break; case R.id.rl_baojai: new GetMyWalletInfo(getContext(), "com.home.baojia").getMyWallet(); break; } }



    推荐阅读