Java tutorial
/** * Copyright 2014 Kakao Corp. * * Redistribution and modification in source or binary forms are not permitted without specific prior written permission. * * 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.kakao; import android.app.Application; import android.graphics.Bitmap; import android.support.v4.util.LruCache; import com.android.volley.RequestQueue; import com.android.volley.toolbox.ImageLoader; import com.android.volley.toolbox.Volley; import com.kakao.helper.SystemInfo; import com.kakao.helper.Utility; /** * ? ? ? ? ??. * * @author MJ */ public class GlobalApplication extends Application { static final String APP_KEY_PROPERTY = "com.kakao.sdk.AppKey"; private static volatile GlobalApplication instance = null; private ImageLoader imageLoader; private String appKey; /** * singleton ? ? . * @return singleton ? ? */ public static GlobalApplication getGlobalApplicationContext() { if (instance == null) throw new IllegalStateException("this application does not inherit com.kakao.GlobalApplication"); return instance; } /** * ? ?, ? ?, ?? . */ @Override public void onCreate() { super.onCreate(); instance = this; SystemInfo.initialize(); final RequestQueue requestQueue = Volley.newRequestQueue(this); ImageLoader.ImageCache imageCache = new ImageLoader.ImageCache() { final LruCache<String, Bitmap> imageCache = new LruCache<String, Bitmap>(3); @Override public void putBitmap(String key, Bitmap value) { imageCache.put(key, value); } @Override public Bitmap getBitmap(String key) { return imageCache.get(key); } }; imageLoader = new ImageLoader(requestQueue, imageCache); appKey = Utility.getMetadata(this, APP_KEY_PROPERTY); } /** * ? ? . * @return ? ? */ public ImageLoader getImageLoader() { return imageLoader; } public String getAppKey() { return appKey; } /** * ? singleton ? ? . */ @Override public void onTerminate() { super.onTerminate(); instance = null; } }