久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

單例模式在android中的應用

項目演示及講解 

創(chuàng)新互聯(lián)公司主營沿河網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP軟件開發(fā),沿河h5重慶小程序開發(fā)搭建,沿河網(wǎng)站營銷推廣歡迎沿河等地區(qū)企業(yè)咨詢

愛奇藝  http://www.iqiyi.com/w_19rtfb03pp.html

土豆 http://www.tudou.com/programs/view/M1R6cIW15DY/

項目下載

http://download.csdn.net/detail/u010134178/9052163

什么是單例模式

百度“java 單例”

以下是通過一個簡單的列子來說明它的用戶,別看這簡單的例子,在公司項目里這可是最基本的呀

1、一個圖片池類

public class ImagePool {

	private static Context mContext;

	private static Bitmap mBitmap;

	private static ImagePool mInstance;

	public ImagePool(Context context) {
		mContext = context;
		mBitmap = BitmapFactory.decodeStream(context.getResources()
				.openRawResource(R.drawable.zheng));
	}

	public static ImagePool getInstance(Context context) {
		if (null == mInstance) {
			mInstance = new ImagePool(context);
		}
		return mInstance;
	}

	public static ImagePool getInstance() {
		return mInstance;
	}

	/**
	 * 外部數(shù)據(jù)接口
	 * 
	 * @return
	 */
	public Bitmap getBitmap() {
		return mBitmap;
	}

	/**
	 * 設(shè)置
	 * 
	 * @return
	 */
	public void setBitmap(int id) {
		mBitmap = BitmapFactory.decodeStream(mContext.getResources()
				.openRawResource(id));
	}

}

一個Applaction層的全局變量

public class MyApplication extends Application{

	@Override
	public void onCreate() {
		super.onCreate();
		//init
		ImagePool.getInstance(getApplicationContext());
	}

}

在業(yè)務(wù)中的基本用法

public class MainActivity extends Activity {  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
  
        final ImageView p_w_picpath = (ImageView) findViewById(R.id.p_w_picpathId);  
        Button change = (Button) findViewById(R.id.changeId);  
        Button start = (Button) findViewById(R.id.startId);  
  
        Drawable drawable = new BitmapDrawable(ImagePool.getInstance()  
                .getBitmap());  
        p_w_picpath.setBackgroundDrawable(drawable);  
  
        change.setOnClickListener(new OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                ImagePool.getInstance().setBitmap(R.drawable.chuan);  
                Drawable drawable = new BitmapDrawable(ImagePool.getInstance()  
                        .getBitmap());  
                p_w_picpath.setBackgroundDrawable(drawable);  
            }  
        });  
  
        start.setOnClickListener(new OnClickListener() {  
            @Override  
            public void onClick(View v) {  
                Intent intent = new Intent(MainActivity.this,  
                        OtherActivity.class);  
                startActivity(intent);  
            }  
        });  
  
    }  
  
}

好了,其實就這么簡單。

當前名稱:單例模式在android中的應用
分享地址:http://sd-ha.com/article28/jggojp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、響應式網(wǎng)站、做網(wǎng)站、App設(shè)計、網(wǎng)站設(shè)計公司企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司