Commit b641fe1836d60ddf2fd8f0b5bf71da0d428d59d0
Exists in
yxb_dev
and in
2 other branches
Merge branch 'developer' of http://git.shunzhi.net/taohd/parentwork into developer
Showing
2 changed files
with
54 additions
and
8 deletions
Show diff stats
.idea/modules.xml
... | ... | @@ -4,8 +4,8 @@ |
4 | 4 | <modules> |
5 | 5 | <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> |
6 | 6 | <module fileurl="file://$PROJECT_DIR$/mvpsdk/mvpsdk.iml" filepath="$PROJECT_DIR$/mvpsdk/mvpsdk.iml" /> |
7 | + <module fileurl="file://$PROJECT_DIR$/parentWorkHolper.iml" filepath="$PROJECT_DIR$/parentWorkHolper.iml" /> | |
7 | 8 | <module fileurl="file://E:\parentwork\parentWorkHolper.iml" filepath="E:\parentwork\parentWorkHolper.iml" /> |
8 | - <module fileurl="file://$PROJECT_DIR$/parentwork.iml" filepath="$PROJECT_DIR$/parentwork.iml" /> | |
9 | 9 | <module fileurl="file://F:\parentWorkHolper\parentwork.iml" filepath="F:\parentWorkHolper\parentwork.iml" /> |
10 | 10 | <module fileurl="file://$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" filepath="$PROJECT_DIR$/roundedimageview-2.2.1/roundedimageview-2.2.1.iml" /> |
11 | 11 | </modules> | ... | ... |
app/src/main/java/com/shunzhi/parent/AppContext.java
1 | 1 | package com.shunzhi.parent; |
2 | 2 | |
3 | +import android.app.ActivityManager; | |
3 | 4 | import android.content.Context; |
4 | 5 | import android.content.Intent; |
5 | 6 | import android.content.SharedPreferences; |
7 | +import android.text.TextUtils; | |
6 | 8 | |
7 | 9 | import com.amap.api.location.AMapLocation; |
8 | 10 | import com.amap.api.location.AMapLocationClient; |
... | ... | @@ -52,19 +54,22 @@ public class AppContext extends GlobalApplication { |
52 | 54 | public AMapLocationClientOption mLocationOption = null; |
53 | 55 | |
54 | 56 | private MessageManager messageManager; |
57 | + | |
55 | 58 | @Override |
56 | 59 | public void onCreate() { |
57 | 60 | appContext = this; |
58 | 61 | super.onCreate(); |
59 | - //开启地图地位 | |
60 | - initMapLocal(); | |
61 | 62 | NIMClient.init(this, loginInfo(), options()); |
62 | - initDB(); | |
63 | - RetrofitCreateHelper.getInstance().setAuthorization(AppConfig.getAppConfig(this).get(AppConfig.ACCESS_TOKEN)); | |
64 | - messageManager = MessageManager.getInstance(); | |
63 | + if (inMainProcess(this)) { | |
64 | + //开启地图地位 | |
65 | + initMapLocal(); | |
66 | + initDB(); | |
67 | + RetrofitCreateHelper.getInstance().setAuthorization(AppConfig.getAppConfig(this).get(AppConfig.ACCESS_TOKEN)); | |
68 | + messageManager = MessageManager.getInstance(); | |
69 | + } | |
65 | 70 | } |
66 | 71 | |
67 | - public MessageManager getMessageManager(){ | |
72 | + public MessageManager getMessageManager() { | |
68 | 73 | return messageManager; |
69 | 74 | } |
70 | 75 | |
... | ... | @@ -103,6 +108,46 @@ public class AppContext extends GlobalApplication { |
103 | 108 | return null; |
104 | 109 | } |
105 | 110 | |
111 | + public static boolean inMainProcess(Context context) { | |
112 | + String packageName = context.getPackageName(); | |
113 | + String processName = getProcessName(context); | |
114 | + return packageName.equals(processName); | |
115 | + } | |
116 | + | |
117 | + /** | |
118 | + * 获取当前进程名 | |
119 | + * | |
120 | + * @param context | |
121 | + * @return 进程名 | |
122 | + */ | |
123 | + public static final String getProcessName(Context context) { | |
124 | + String processName = null; | |
125 | + | |
126 | + // ActivityManager | |
127 | + ActivityManager am = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)); | |
128 | + | |
129 | + while (true) { | |
130 | + for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) { | |
131 | + if (info.pid == android.os.Process.myPid()) { | |
132 | + processName = info.processName; | |
133 | + break; | |
134 | + } | |
135 | + } | |
136 | + | |
137 | + // go home | |
138 | + if (!TextUtils.isEmpty(processName)) { | |
139 | + return processName; | |
140 | + } | |
141 | + | |
142 | + // take a rest and again | |
143 | + try { | |
144 | + Thread.sleep(100L); | |
145 | + } catch (InterruptedException ex) { | |
146 | + ex.printStackTrace(); | |
147 | + } | |
148 | + } | |
149 | + } | |
150 | + | |
106 | 151 | private void initMapLocal() { |
107 | 152 | //初始化定位 |
108 | 153 | mLocationClient = new AMapLocationClient(getApplicationContext()); |
... | ... | @@ -170,7 +215,8 @@ public class AppContext extends GlobalApplication { |
170 | 215 | sendBroadcast(intent); |
171 | 216 | stopLocation(); |
172 | 217 | } else { |
173 | - cityName = "定位失败";district="定位失败"; | |
218 | + cityName = "定位失败"; | |
219 | + district = "定位失败"; | |
174 | 220 | |
175 | 221 | // Log.d("mlocation:","errorCode="+aMapLocation.getErrorCode()+"errorInfo="+aMapLocation.getErrorInfo()); |
176 | 222 | } | ... | ... |