Pārlūkot izejas kodu

优化部分可能导致内存泄漏的问题

1.添加ButterKnife框架的解绑机制
2.修改ActMain(首页)的启动模式
3.修改WebViewAct退出时释放WebView
4.修改SheepApp中Activity退出时的销毁策略
5.修改ActivityManager中的Activity销毁释放顺序
6.修复FeedBackAct中视图重复绑定的问题
zhoujuncai 7 gadi atpakaļ
vecāks
revīzija
e7f3b3d467

+ 15 - 8
app/src/main/java/com/sheep/gamegroup/absBase/BaseActivity.java

@@ -3,12 +3,12 @@ package com.sheep.gamegroup.absBase;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
-import android.view.KeyEvent;
 
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.view.dialog.DialogLoading;
 
 import butterknife.ButterKnife;
+import butterknife.Unbinder;
 
 /**
  * Created by kemllor on 2017/12/15.
@@ -17,13 +17,13 @@ import butterknife.ButterKnife;
 public abstract class BaseActivity extends AppCompatActivity {
 
     protected DialogLoading dialogLoading;
-
+    public Unbinder bind;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(getLayoutId());
-        ButterKnife.bind(this);
+        bind = ButterKnife.bind(this);
         initView();
         initListener();
         initData();
@@ -58,7 +58,7 @@ public abstract class BaseActivity extends AppCompatActivity {
     protected void onResume() {
         super.onResume();
         Object action = DataUtil.getInstance().getAction(getClass().getSimpleName());
-        if(action != null){
+        if (action != null) {
             doNextAction(action);
         }
     }
@@ -67,16 +67,23 @@ public abstract class BaseActivity extends AppCompatActivity {
 
     public abstract void initView();
 
-    public void initListener(){
+    public void initListener() {
 
     }
 
-    public void initData(){
+    public void initData() {
 
     }
-    public void doNextAction(Object action){
 
-    }
+    public void doNextAction(Object action) {
 
+    }
 
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        if (this.bind != null) {
+            this.bind.unbind();
+        }
+    }
 }

+ 32 - 24
app/src/main/java/com/sheep/gamegroup/util/ActivityManager.java

@@ -15,96 +15,104 @@ public class ActivityManager {
     private static Stack<Activity> activityStack = new Stack<>();
     private static ActivityManager activityManager;
 
-    public static ActivityManager getInstance(){
-        if(activityManager == null)
+    public static ActivityManager getInstance() {
+        if (activityManager == null)
             activityManager = new ActivityManager();
         return activityManager;
     }
+
     /**
      * 将activity移除stack
      */
-    public void popActivity(Activity activity){
-        if (activity != null){
+    public void popActivity(Activity activity) {
+        if (activity != null) {
             activityStack.remove(activity);
         }
     }
+
     /**
      * 结束制定activity
      */
-    public void endActivity(Activity activity){
-        if(activity != null){
-            activity.finish();
+    public void endActivity(Activity activity) {
+        if (activity != null) {
             activityStack.remove(activity);
+            activity.finish();
         }
     }
+
     /**
      * 结束制定activity
      */
-    public void endActivity(Class<? extends Activity> cls){
-        try{
-            for(Activity activity: activityStack){
-                if(activity.getClass().equals(cls)){
+    public void endActivity(Class<? extends Activity> cls) {
+        try {
+            for (Activity activity : activityStack) {
+                if (activity.getClass().equals(cls)) {
                     endActivity(activity);
                 }
             }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
     }
+
     /**
      * 活的当前的activity(即最上层)
      */
-    public Activity currentActivity(){
+    public Activity currentActivity() {
         Activity activity = null;
-        if(!activityStack.empty()){
+        if (!activityStack.empty()) {
             activity = activityStack.lastElement();
         }
         return activity;
     }
+
     /**
      * 讲activity 推入栈内
      */
-    public void pushActivity(Activity activity){
+    public void pushActivity(Activity activity) {
         if (activityStack == null) {
             activityStack = new Stack<>();
         }
         activityStack.add(activity);
     }
+
     /**
      * 弹出class外的所有activity
      */
-    public void popAllActivityExceptThis(Class<? extends Activity> cls){
-        while (true){
+    public void popAllActivityExceptThis(Class<? extends Activity> cls) {
+        while (true) {
             Activity activity = currentActivity();
             if (activity == null) {
                 break;
             }
-            if (activity.getClass().equals(cls)){
+            if (activity.getClass().equals(cls)) {
                 break;
             }
             popActivity(activity);
         }
     }
+
     /**
      * 结束除cls之外的所有activity,将执行结果都会清空stack
      */
-    public void finishAllActivityExceptThis(Class<? extends Activity> cls){
+    public void finishAllActivityExceptThis(Class<? extends Activity> cls) {
         while (!activityStack.empty()) {
             Activity activity = currentActivity();
-            if(activity.getClass().equals(cls)){
+            if (activity.getClass().equals(cls)) {
                 popActivity(activity);
-            }else {
+            } else {
                 endActivity(activity);
             }
         }
     }
+
     /**
      * 结束所有activity
      */
-    public void finishAllActivity(){
-        while (!activityStack.empty()){
+    public void finishAllActivity() {
+        while (!activityStack.empty()) {
             Activity activity = currentActivity();
-                endActivity(activity);
+            endActivity(activity);
         }
     }
 }

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 281 - 179
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java


+ 1 - 1
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -108,7 +108,7 @@ public class TestUtil {
                                     if(object instanceof LoginUser){
                                         SpUtils.saveToken(SheepApp.getInstance(), ((LoginUser) object).getToken());
                                         ActivityManager.getInstance().finishAllActivity();
-                                        Intent intent = new Intent(SheepApp.getInstance(), ActMain.class);
+                                        Intent intent = new Intent(SheepApp.getInstance(), ActMain.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                         SheepApp.getInstance().startActivity(intent);
                                     } else {

+ 78 - 62
app/src/main/java/com/sheep/gamegroup/view/activity/ChangeTelAct.java

@@ -38,7 +38,7 @@ import rx.functions.Action1;
  * Created by ljy on 2018/3/27.
  */
 
-public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
+public class ChangeTelAct extends BaseActivity implements PhoneContract.View {
     @BindView(R.id.tel_tv)
     TextView telTv;
     @BindView(R.id.sure_change_tv)
@@ -88,7 +88,7 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
     private SelfCountDownTimer selfCountDownTimer;
     private boolean canGetCaptchaPhone = true;
 
-    private int where_from ;
+    private int where_from;
 
     @Override
     protected int getLayoutId() {
@@ -115,14 +115,15 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
                         toFinish();
                     }
                 });
-        switch (where_from){
+        switch (where_from) {
             case FROM_SPLASH://非第一次登录(如:登录后直接重启),老用户需要绑定手机号
                 titleBarUtils.setRightBtn(this, "跳过", 0, new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
-                        Intent intent = new Intent(activity, ActMain.class);
-                        activity.startActivity(intent);
-                        activity.finish();
+//                        Intent intent = new Intent(activity, ActMain.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+//                        activity.startActivity(intent);
+//                        activity.finish();
+                        startMainAct();
                     }
                 });
                 break;
@@ -133,9 +134,10 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
                         Jump2View.getInstance().checkLabel(activity, new Action1<BaseMessage>() {
                             @Override
                             public void call(BaseMessage baseMessage) {
-                                Intent intent = new Intent(activity, ActMain.class);
-                                activity.startActivity(intent);
-                                activity.finish();
+//                                Intent intent = new Intent(activity, ActMain.class);
+//                                activity.startActivity(intent);
+//                                activity.finish();
+                                startMainAct();
                             }
                         });
                     }
@@ -146,7 +148,7 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
                 break;
         }
         mobiles = DataUtil.getInstance().getUserMobile();
-        if(!TextUtils.isEmpty(mobiles)){//提示
+        if (!TextUtils.isEmpty(mobiles)) {//提示
             oldOrNew = 1;
             showChangeLayout.setVisibility(View.VISIBLE);
             changePhoneLayout.setVisibility(View.GONE);
@@ -156,20 +158,31 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
         refreshData();
     }
 
+    /**
+     * 跳转到首页
+     */
+    private void startMainAct() {
+        Intent intent = new Intent(activity, ActMain.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        activity.startActivity(intent);
+        activity.finish();
+    }
+
     private void toFinish() {
-        switch (where_from){
+        switch (where_from) {
             case FROM_SPLASH://非第一次登录(如:登录后直接重启),老用户需要绑定手机号
-                Intent intent = new Intent(activity, ActMain.class);
-                startActivity(intent);
-                finish();
+//                Intent intent = new Intent(activity, ActMain.class);
+//                startActivity(intent);
+//                finish();
+                startMainAct();
                 break;
             case FROM_LOGIN://第一次登录,老用户需要绑定手机号
                 Jump2View.getInstance().checkLabel(activity, new Action1<BaseMessage>() {
                     @Override
                     public void call(BaseMessage baseMessage) {
-                        Intent intent = new Intent(activity, ActMain.class);
-                        activity.startActivity(intent);
-                        activity.finish();
+//                        Intent intent = new Intent(activity, ActMain.class);
+//                        activity.startActivity(intent);
+//                        activity.finish();
+                        startMainAct();
                     }
                 });
                 break;
@@ -214,39 +227,39 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
     /**
      * refresh
      */
-    public void refreshData(){
+    public void refreshData() {
         showChangeLayout.setVisibility(View.GONE);
         changePhoneLayout.setVisibility(View.VISIBLE);
-        if(oldOrNew == 1){
+        if (oldOrNew == 1) {
             hitStr = "请输入手机号码";
             noticeStr = "验证原手机";
-            phoneEtAccount.setHint(hitStr+"");
+            phoneEtAccount.setHint(hitStr + "");
 //            phoneEtAccount.setText(mobiles+"");
-        }else{
+        } else {
             step = 0;
             hitStr = "请输入手机号码";
             noticeStr = "绑定手机号";
-            phoneEtAccount.setHint(hitStr+"");
+            phoneEtAccount.setHint(hitStr + "");
             TitleBarUtils.getInstance().setTitle(this, noticeStr);
         }
     }
 
-    @OnClick({ R.id.phone_btn_code, R.id.phone_sure_tv, R.id.sure_change_tv, R.id.phone_btn_code_old})
+    @OnClick({R.id.phone_btn_code, R.id.phone_sure_tv, R.id.sure_change_tv, R.id.phone_btn_code_old})
     public void onViewClicked(View view) {
         switch (view.getId()) {
             case R.id.phone_btn_code:
                 sec_code = null;
-                mobile = phoneEtAccount.getText().toString() +"";
-                if(!checkPhoneInput(mobile)){
+                mobile = phoneEtAccount.getText().toString() + "";
+                if (!checkPhoneInput(mobile)) {
                     return;
                 }
                 if (!canGetCaptchaPhone) {
                     return;
                 }
-                if(oldOrNew == 0){
+                if (oldOrNew == 0) {
                     selfCountDownTimer.reset(SelfCountDownTimer.FULL_SECOND);
                     JSONObject jsonObject = new JSONObject();
-                    jsonObject.put("mobile", mobile+"");
+                    jsonObject.put("mobile", mobile + "");
                     presenter.smsBindMobile(jsonObject);
                     canGetCaptchaPhone = false;
                     selfCountDownTimer.start();
@@ -256,18 +269,18 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
                 submit();
                 break;
             case R.id.phone_sure_tv://更换手机号
-                sec_code = phoneEtCode.getText().toString()+"";
-                mobile = phoneEtAccount.getText().toString() +"";
-                if(!checkPhoneInput(mobile)){
+                sec_code = phoneEtCode.getText().toString() + "";
+                mobile = phoneEtAccount.getText().toString() + "";
+                if (!checkPhoneInput(mobile)) {
                     return;
                 }
-                if(!checkCodeInput(sec_code)){
+                if (!checkCodeInput(sec_code)) {
                     return;
                 }
-                if(oldOrNew == 0){
+                if (oldOrNew == 0) {
                     JSONObject jsonObject = new JSONObject();
-                    jsonObject.put("mobile", mobile+"");
-                    jsonObject.put("sec_code", sec_code+"");
+                    jsonObject.put("mobile", mobile + "");
+                    jsonObject.put("sec_code", sec_code + "");
                     presenter.bindPhone(jsonObject);
                     return;
                 }
@@ -276,8 +289,8 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
                 UMConfigUtils.onEvent(UMConfigUtils.Event.USER_BIND_PHONE);
                 break;
             case R.id.sure_change_tv:
-                sec_code = phone_et_code_old.getText().toString()+"";
-                if(!checkCodeInput(sec_code)){
+                sec_code = phone_et_code_old.getText().toString() + "";
+                if (!checkCodeInput(sec_code)) {
                     return;
                 }
                 step = 2;
@@ -298,10 +311,10 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
     /**
      * 提交
      */
-    private void submit(){
+    private void submit() {
         JSONObject jsonObject = new JSONObject();
-        jsonObject.put("step", step+"");
-        switch (step){
+        jsonObject.put("step", step + "");
+        switch (step) {
             case 1:
 
                 selfCountDownTimer.reset(SelfCountDownTimer.FULL_SECOND);
@@ -309,19 +322,19 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
                 selfCountDownTimer.start();
                 break;
             case 2:
-                jsonObject.put("sec_code", sec_code+"");
+                jsonObject.put("sec_code", sec_code + "");
                 break;
             case 3:
-                jsonObject.put("auth_code", auth_code+"");
-                jsonObject.put("mobile", mobile+"");
+                jsonObject.put("auth_code", auth_code + "");
+                jsonObject.put("mobile", mobile + "");
                 selfCountDownTimer.reset(SelfCountDownTimer.FULL_SECOND);
                 canGetCaptchaPhone = false;
                 selfCountDownTimer.start();
                 break;
             case 4:
-                jsonObject.put("sec_code", sec_code+"");
-                jsonObject.put("auth_code", auth_code+"");
-                jsonObject.put("mobile", mobile+"");
+                jsonObject.put("sec_code", sec_code + "");
+                jsonObject.put("auth_code", auth_code + "");
+                jsonObject.put("mobile", mobile + "");
                 break;
         }
         presenter.switchPhone(jsonObject);
@@ -350,67 +363,68 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
 
     @Override
     public void changeTelSuccess(BaseMessage o) {
-        try{
+        try {
 //            if(step == 1 || step == 3){
 //                changeTelSuccess
 //            }
-            if(step == 2){
+            if (step == 2) {
                 oldOrNew = 1;
 
 //                handler.sendEmptyMessage(CHANGGE_CLICK);
                 refreshData();
                 phoneBtnCode.setText(getString(R.string.get_captcha));
                 canGetCaptchaPhone = true;
-                if(selfCountDownTimer != null)
+                if (selfCountDownTimer != null)
                     selfCountDownTimer.reset(SelfCountDownTimer.FULL_SECOND);
-            }else if(step == 4){
+            } else if (step == 4) {
                 DataUtil.getInstance().setUserMobile(mobile);
                 G.showToast(o);
                 CommonUtil.getInstance().updateUserInfo(null);
                 finish();
             }
-            if(o == null){
+            if (o == null) {
                 G.showToast("网络错误");
                 return;
             }
-            if(o.getData() == null || o.getData().equals("")){
+            if (o.getData() == null || o.getData().equals("")) {
 //                G.showToast(o.getMsg()+"");
                 return;
             }
-            G.showToast((o.getMsg()).equals("")?"提交成功":o.getMsg()+"");
+            G.showToast((o.getMsg()).equals("") ? "提交成功" : o.getMsg() + "");
             JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(o.getData()));
             auth_code = jsonObject.getString("auth_code");
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
     }
 
     @Override
     public void changeTelFail(BaseMessage o) {
-        if(o == null){
+        if (o == null) {
             G.showToast("网络错误");
             return;
         }
-        G.showToast(o.getMsg()+"");
+        G.showToast(o.getMsg() + "");
     }
 
     @Override
     public void bindTelSuccess(BaseMessage o) {
         G.showToast(o);
-        switch (where_from){
+        switch (where_from) {
             case FROM_LOGIN:
             case 30001:
                 Jump2View.getInstance().checkLabel(activity, new Action1<BaseMessage>() {
                     @Override
                     public void call(BaseMessage baseMessage) {
-                        Intent intent = new Intent(activity, ActMain.class);
-                        activity.startActivity(intent);
-                        activity.finish();
+//                        Intent intent = new Intent(activity, ActMain.class);
+//                        activity.startActivity(intent);
+//                        activity.finish();
+                        startMainAct();
                     }
                 });
                 break;
             case FROM_SPLASH://非第一次登录(如:登录后直接重启),老用户需要绑定手机号
-                Intent intent = new Intent(activity, ActMain.class);
+                Intent intent = new Intent(activity, ActMain.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 startActivity(intent);
             default:
                 finish();
@@ -420,7 +434,7 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
 
     @Override
     public void bindTelFail(BaseMessage o) {
-        G.showToast(o.getMsg()+"");
+        G.showToast(o.getMsg() + "");
     }
 
     @Override
@@ -447,6 +461,7 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
         }
         return true;
     }
+
     private boolean checkCodeInput(String etCode) {
         if (TextUtils.isEmpty(etCode)) {
             G.showToast(getString(R.string.input_your_captcha));
@@ -467,10 +482,11 @@ public class ChangeTelAct extends BaseActivity implements PhoneContract.View{
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        if(selfCountDownTimer != null){
+        if (selfCountDownTimer != null) {
             selfCountDownTimer.cancel();
         }
     }
+
     public static final int FROM_LOGIN = 1;//第一次登录,老用户需要绑定手机号
     public static final int FROM_SPLASH = 2;//非第一次登录(如:登录后直接重启),老用户需要绑定手机号
 }

+ 7 - 8
app/src/main/java/com/sheep/gamegroup/view/activity/FeedbackAct.java

@@ -13,7 +13,6 @@ import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
 
 import butterknife.BindView;
-import butterknife.ButterKnife;
 import butterknife.OnClick;
 import rx.android.schedulers.AndroidSchedulers;
 import rx.schedulers.Schedulers;
@@ -61,21 +60,21 @@ public class FeedbackAct extends BaseActivity {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         // TODO: add setContentView(...) invocation
-        ButterKnife.bind(this);
+//        this.bind = ButterKnife.bind(this);
     }
 
     @OnClick(R.id.tv_submit)
     public void onViewClicked() {
         USER_FEEDBACK_COMMIT.onEvent();
-        Content = feedbookEt.getText() +"";
-        Email = feedbookEmailEt.getText() +"";
-        if(android.text.TextUtils.isEmpty(Content)){
+        Content = feedbookEt.getText() + "";
+        Email = feedbookEmailEt.getText() + "";
+        if (android.text.TextUtils.isEmpty(Content)) {
             G.showToast(getResources().getString(R.string.feedback_notice_input_advice));
             return;
         }
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("Content", Content);
-        jsonObject.put("Email", Email+"");
+        jsonObject.put("Email", Email + "");
         SheepApp.getInstance()
                 .getNetComponent()
                 .getApiService()
@@ -85,12 +84,12 @@ public class FeedbackAct extends BaseActivity {
                 .subscribe(new SheepSubscriber<BaseMessage>(this) {
                     @Override
                     public void onError(BaseMessage baseMessage) {
-                        G.showToast(baseMessage.getMsg() +"");
+                        G.showToast(baseMessage.getMsg() + "");
                     }
 
                     @Override
                     public void onNext(BaseMessage baseMessage) {
-                        G.showToast(baseMessage.getMsg() +"");
+                        G.showToast(baseMessage.getMsg() + "");
                         finish();
                     }
                 });

+ 6 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/WebviewAct.java

@@ -151,4 +151,10 @@ public class WebviewAct extends BaseActivity {
         }
 
     }
+
+    @Override
+    protected void onDestroy() {
+        activityWebview.destroy();
+        super.onDestroy();
+    }
 }

+ 28 - 23
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -15,15 +15,17 @@ import com.baidu.location.BDAbstractLocationListener;
 import com.baidu.location.BDLocation;
 import com.baidu.location.LocationClient;
 import com.baidu.location.LocationClientOption;
-import com.sheep.gamegroup.util.CertificationUtil;
-import com.sheep.gamegroup.util.ConfigUtil;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.GlideBuilder;
 import com.sheep.gamegroup.di.components.DaggerNetComponent;
 import com.sheep.gamegroup.di.components.NetComponent;
 import com.sheep.gamegroup.di.modules.NetModule;
 import com.sheep.gamegroup.usage.AppUsageManager;
 import com.sheep.gamegroup.util.ActivityManager;
 import com.sheep.gamegroup.util.AppUtil;
+import com.sheep.gamegroup.util.CertificationUtil;
 import com.sheep.gamegroup.util.ChannelContent;
+import com.sheep.gamegroup.util.ConfigUtil;
 import com.sheep.gamegroup.util.ConnectAddress;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
@@ -32,7 +34,6 @@ import com.sheep.gamegroup.util.RefreshUtil;
 import com.sheep.gamegroup.util.ScreenShotListenManager;
 import com.sheep.gamegroup.util.SysAppUtil;
 import com.sheep.gamegroup.util.UMConfigUtils;
-import com.sheep.gamegroup.view.activity.ActBindMobileRegister;
 import com.sheep.gamegroup.view.activity.ActMain;
 import com.sheep.gamegroup.view.activity.GameCertificationActivity;
 import com.sheep.gamegroup.view.activity.LoginAct;
@@ -142,20 +143,20 @@ public class SheepApp extends MultiDexApplication {
     }
 
     public void setConnectAddress(ConnectAddress connectAddress) {
-            if(this.connectAddress != connectAddress){
-                DataUtil.putAsString("flavor", connectAddress.name());
-                quit();
-                android.os.Process.killProcess(android.os.Process.myPid());
-                System.exit(0);
-            } else {
-                G.showToast("已经是该服务器");
-            }
+        if (this.connectAddress != connectAddress) {
+            DataUtil.putAsString("flavor", connectAddress.name());
+            quit();
+            android.os.Process.killProcess(android.os.Process.myPid());
+            System.exit(0);
+        } else {
+            G.showToast("已经是该服务器");
+        }
     }
 
     @Override
     public void onCreate() {
         super.onCreate();
-        if(AppUtil.isMainProcess(this)) {
+        if (AppUtil.isMainProcess(this)) {
             mSheepApp = this;
             connectAddress = ConnectAddress.sheep.getDefultConnectAddress();
             registerActivityLifecycleCallbacks(activityLifecycleCallbacks);
@@ -309,6 +310,7 @@ public class SheepApp extends MultiDexApplication {
         mLocationClient.restart();
         return curLocation;
     }
+
     private void initNet() {
         netComponent = DaggerNetComponent.builder().netModule(new NetModule()).build();
     }
@@ -321,12 +323,13 @@ public class SheepApp extends MultiDexApplication {
      */
     ActivityLifecycleCallbacks activityLifecycleCallbacks = new ActivityLifecycleCallbacks() {
         private ScreenShotListenManager manager;
+
         @Override
         public void onActivityCreated(final Activity activity, Bundle savedInstanceState) {
             ActivityManager.getInstance().pushActivity(activity);
-            if(/*activity instanceof SplashAct || */activity instanceof LoginAct){
+            if (/*activity instanceof SplashAct || */activity instanceof LoginAct) {
                 SysAppUtil.showVersionInfo(activity, SpUtils.getIgnoreMd5());
-            } else if(activity instanceof ActMain){
+            } else if (activity instanceof ActMain) {
                 SysAppUtil.showVersionInfo(activity, SpUtils.getIgnoreMd5(), new Action1<Integer>() {
                     @Override
                     public void call(Integer integer) {
@@ -335,14 +338,14 @@ public class SheepApp extends MultiDexApplication {
                 });
             }
 
-            if(mActivityCount == 0) {
-                if(ConfigUtil.getInstance().isUpgrade()) {
+            if (mActivityCount == 0) {
+                if (ConfigUtil.getInstance().isUpgrade()) {
                     Beta.autoDownloadOnWifi = !BuildConfig.DEBUG;
                     Bugly.init(getApplicationContext(), Config.BUGLY_APPID, BuildConfig.DEBUG);
                 }
                 AppUsageManager.getInstance().needOpenLookAppUsageStatsPermisson(true);//尝试保存应用使用情况的数据
                 LogUtil.println("SheepApp onActivityCreated", mActivityCount);
-                if(DataUtil.IS_LISTEN_SCREEN_SHOT) {
+                if (DataUtil.IS_LISTEN_SCREEN_SHOT) {
                     manager = ScreenShotListenManager.newInstance(activity.getApplicationContext());
                     manager.setListener(
                             new ScreenShotListenManager.OnScreenShotListener() {
@@ -362,7 +365,7 @@ public class SheepApp extends MultiDexApplication {
             mActivityCount++;
             UMConfigUtils.onPageStart(activity);
             if (mActivityCount > 0) {
-                if(!notStop) {
+                if (!notStop) {
                     notStop = true;
                     LogUtil.println("SheepApp onActivityStarted", mActivityCount);
                     UMConfigUtils.Event.SHEEP_STARTED.onEvent();
@@ -386,7 +389,7 @@ public class SheepApp extends MultiDexApplication {
             mActivityCount--;
             UMConfigUtils.onPageEnd(activity);
             if (mActivityCount <= 0) {
-                if(notStop) {
+                if (notStop) {
                     notStop = false;
                     LogUtil.println("SheepApp onActivityStopped", mActivityCount);
                     UMConfigUtils.Event.SHEEP_STOPPED.onEvent();
@@ -403,20 +406,21 @@ public class SheepApp extends MultiDexApplication {
         @Override
         public void onActivityDestroyed(Activity activity) {
             Log.e("act_destroy_----", "in");
-            if(!TextUtils.isEmpty(gamePackgeName) && isGameFlag() && (activity instanceof GameCertificationActivity ||activity instanceof LoginAct)){
+            if (!TextUtils.isEmpty(gamePackgeName) && isGameFlag() && (activity instanceof GameCertificationActivity || activity instanceof LoginAct)) {
                 CertificationUtil.newInstance().doCertification(activity, gamePackgeName, "cancel");
             }
-            if(mActivityCount == 0) {
+            if (mActivityCount == 0) {
                 LogUtil.println("SheepApp onActivityDestroyed", mActivityCount);
                 DataUtil.getInstance().resetIsNewSmallSheep();
                 stopService(new Intent(SheepApp.this, DownloadService.class));
                 stopService(new Intent(SheepApp.this, FloatService.class));
-                if(DataUtil.IS_USE_SCREEN_SHOT)
+                if (DataUtil.IS_USE_SCREEN_SHOT)
                     stopService(new Intent(SheepApp.this, FloatShotScreenService.class));
-                if(manager != null)
+                if (manager != null)
                     manager.stopListen();
                 UMConfigUtils.Event.SHEEP_DESTROYED.onEvent();
             }
+            ActivityManager.getInstance().endActivity(activity);
         }
     };
 
@@ -430,6 +434,7 @@ public class SheepApp extends MultiDexApplication {
         } catch (Exception ignore) {
         }
     }
+
     public NetComponent getNetComponent() {
         return netComponent;
     }