Java tutorial
/******************************************************************************* * Copyright 2011-2013 Sergey Tarasevich * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ package com.common.app; import android.content.Context; import android.support.multidex.MultiDex; import android.support.multidex.MultiDexApplication; import android.support.v4.app.FragmentActivity; import com.baidu.mapapi.SDKInitializer; import com.common.app.degexce.CrashHandler; import com.common.app.degexce.L; import com.easemob.redpacketsdk.RedPacket; import com.hyphenate.chatuidemo.DemoHelper; import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.nostra13.universalimageloader.core.assist.QueueProcessingType; import java.util.ArrayList; import java.util.List; import cn.jpush.android.api.JPushInterface; import cn.lanmei.com.dingdong.R; /** * @author Sergey Tarasevich (nostra13[at]gmail[dot]com) */ public class MyApplication extends MultiDexApplication { private String TAG = "MyApplication"; private static MyApplication instance; /** * nickname for current user, the nickname instead of ID be shown when user receive notification from APNs */ public static String currentUserNick = ""; public static int placeholder = R.drawable.img_default; private List<FragmentActivity> recordsFA = new ArrayList<>(); @Override public void onCreate() { super.onCreate(); CrashHandler crashHandler = CrashHandler.getInstance(); crashHandler.init(getApplicationContext()); MultiDex.install(this); //init demo helper instance = this; SDKInitializer.initialize(instance); //init demo helper DemoHelper.getInstance().init(instance); //red packet code : ?? RedPacket.getInstance().initContext(instance); RedPacket.getInstance().setDebugMode(false); //end of red packet code initImageLoader(instance); JPushInterface.setDebugMode(false); // ?,? JPushInterface.init(this); // ? JPush } @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } public static MyApplication getInstance() { if (instance != null) return instance; return null; } public static void initImageLoader(Context context) { // This configuration tuning is custom. You can tune every option, you may tune some of them, // or you can create default configuration by // ImageLoaderConfiguration.createDefault(this); // method. ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory() .discCacheFileNameGenerator(new Md5FileNameGenerator()) .tasksProcessingOrder(QueueProcessingType.LIFO).writeDebugLogs() // Remove for release app .build(); // Initialize ImageLoader with configuration. ImageLoader.getInstance().init(config); } public void addActvity(FragmentActivity activity) { recordsFA.add(activity); L.MyLog(TAG, activity.getClass().getName() + "---Current Acitvity Size :" + getCurrentActivitySize()); } public void removeActvity(FragmentActivity activity) { recordsFA.remove(activity); L.MyLog(TAG, activity.getClass().getName() + "---Current Acitvity Size :" + getCurrentActivitySize()); } public void exit() { for (FragmentActivity activity : recordsFA) { activity.finish(); } } public int getCurrentActivitySize() { return recordsFA.size(); } public static String getUid() { return SharePreferenceUtil.getString("myUid", "0"); } public static void setUid(String uid) { SharePreferenceUtil.putString("myUid", uid); } public static String getUserType() { return SharePreferenceUtil.getString("UserType", "1"); } public static void setUserType(String userType) { SharePreferenceUtil.putString("UserType", userType); } }