¾È±Ô °øºÎ¹æ

Android > Webview - ÄíÅ°(Cookie Session) »ç¿ë½Ã µ¿±âÈ­ ¹æ¹ý

µî·ÏÀÏ : 2017-07-06 17:48 Á¶È¸¼ö : 53,062

¾Èµå·ÎÀÌµå ±â¹ÝÀÇ WebView¸¦ »ç¿ëÇÏ´Ù º¸¸é ÄíÅ°¿Í °ü·Ã ºÎºÐÀÇ µ¿ÀÛÀÌ Á¶±Ý ÀÌ»óÇÑ °ÍÀ» ¹ß°ßÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.

¿¹¸¦ µéÀÚ¸é ·Î±×ÀÎÀ» Çߴµ¥ »ç¿ëÁß¿¡ °©Àڱ⠷α×ÀÎÀÌ Ç®·Á¹ö¸°´Ù°Å³ª ·Î±×¾Æ¿ôÀ» ¾Æ¹«¸® Çصµ ·Î±×¾Æ¿ô󸮰¡ µÇÁö ¾Ê´Â ¹®Á¦°¡ ÀÖ½À´Ï´Ù.

ÀÌ·¯ÇÑ ¹®Á¦´Â ½ÇÁ¦·Î ¾îÇø®ÄÉÀ̼ÇÀÌ ÇÒ´ç ¹ÞÀº ¸Þ¸ð¸® ¿µ¿ª(RAM)°ú Àüü Äí±â°¡ º¸°üµÇ´Â Áö¿ª ÀúÀå¼Ò°£ÀÇ µ¿±âÈ­°¡ Á¦´ë·Î

ÀÌ·ç¾îÁöÁö ¸øÇϴµ¥¼­ ¹ß»ýÇÏ´Â ¹®Á¦ÀÔ´Ï´Ù. ´ÙÀ½¿¡¼­ º¸¿©µå¸± CookieSyncManager¸¦ ÀÌ¿ëÇÏ¿© ÀÌ ¹®Á¦¸¦ ÇØ°áÇÒ ¼ö ÀÖ½À´Ï´Ù.
 
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);         
		setContentView(R.layout.main);
			
		CookieSyncManager.createInstance(this);
	}


À§¿Í°°ÀÌ onCreate³»¿¡¼­ ½ÌÅ©¸¦ ½ÃÀÛÇÏ¿© ÁÖµµ·Ï ÇսôÙ. ÀÌ ¸í·ÉÀº ¾îÇø®ÄÉÀ̼ÇÀÇ °¡Àå Host°¡ µÇ´Â ¾×ƼºñƼÀÇ

»ý¼º½Ã¿¡ È£ÃâÇØ ÁÖ½Ã¸é µË´Ï´Ù. ¾×ƼºñƼ¸¶´Ù ¸Å¹ø È£ÃâÇÏ½Ç ÇÊ¿ä°¡ ¾ø½À´Ï´Ù.
 
	
	@Override
	protected void onResume()
	{
		super.onResume();
		CookieSyncManager.getInstance().startSync();
	}
	

À§ÀÇ ¸í·ÉÀ» onResume() ¸Þ¼­µå ¾È¿¡¼­ ±¸ÇöÇØ ÁÖµµ·Ï ÇսôÙ.
 
	@Override
	protected void onPause()
	{
		super.onPause();
	    CookieSyncManager.getInstance().stopSync();
	}

À§ÀÇ ¸í·ÉÀ» onResume() ¸Þ¼­µå ¾È¿¡¼­ ±¸ÇöÇØ ÁÖµµ·Ï ÇսôÙ.
À§ÀÇ ¸í·ÉÀ» onPause() ¸Þ¼­µå ¾È¿¡¼­ ±¸ÇöÇØ ÁÖµµ·Ï ÇսôÙ.

À§¿Í °°Àº °úÁ¤À» ÅëÇØ ¾îÇø®ÄÉÀ̼ÇÀÌ ½ÇÇàµÇ¸é ÄíÅ°½ÌÅ© ¸Å´ÏÀúÀÇ ÀνºÅϽº¸¦ »ý¼ºÇÏ°í ¾îÇø®ÄÉÀ̼ÇÀÌ ÁßÁö »óÅ·Πµé¾î°¡°Ô

µÇ¸é ½ÌÅ©¸¦ ÁߴܽÃÄÑ ¿ÜºÎÀÇ ¾îÇø®ÄÉÀ̼ǿ¡ ÀÇÇØ ÄíÅ°°¡ ²¿À̴°ÍÀ» ¹æÁöÇÏ¿© ÁÝ´Ï´Ù. ÀÌÈÄ¿¡ ¾îÇø®ÄÉÀ̼ÇÀÌ ´Ù½Ã ½ÃÀ۵Ǹé ÄíÅ° µ¿±âÈ­¸¦ Àç½ÃÀÛÇÕ´Ï´Ù.

½ÇÁ¦·Î Á¦ÀÛÇß´ø ¾îÇø®ÄÉÀ̼ÇÀÇ ÄíÅ° ¹®Á¦°¡ “Á¤¸» ¾ÆÁÖ °£ÇæÀû”À¸·Î ¹ß»ýÇؼ­ ¿øÀÎÀ» ã±âµµ ¾î·Á¿ü´Âµ¥ À§¿Í°°Àº 󸮸¦ ÇÏ°í³ª´Ï ¾Æ¹«·± ¹®Á¦¾øÀÌ ÇØ°áÀÌ µÇ¾ú³×¿ä.


¾Æ·¡ ¿¹Á¦´Â ½ÇÁ¦ ÇÁ·ÎÁ§Æ®¿¡¼­ »ç¿ëÇØ ºÃ´ø ¿¹Á¦ ÀÔ´Ï´Ù.

 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webview);
		
		WebView wv = (WebView) findViewById(R.id.webview_test);
		
		/////////////////   ÄíÅ° Àоî¿Í µ¿±âÈ­ ½ÃÅ°´Â ºÎºÐ Ãß°¡  /////////////
		
		Cookie sessionCookie =null;
		
		try {
			if(!SessionControl.cookies.isEmpty())
			{
				sessionCookie=SessionControl.cookies.get(0);       
		
				CookieSyncManager.createInstance(this);
				CookieManager cookieManager = CookieManager.getInstance();
		
				if (sessionCookie != null) 
				{            
					cookieManager.removeSessionCookie();
					String cookieString = sessionCookie.getName() + "=" + sessionCookie.getValue() + "; domain=" + sessionCookie.getDomain();           
					cookieManager.setCookie(myUrlAddress, cookieString);           
					CookieSyncManager.getInstance().sync();
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally
		{			 
		}

		/////////////////

		wv.loadUrl(myUrlAddress);

		}

	public void onResume() {
		super.onResume();
		CookieSyncManager.getInstance().startSync();
	}

	public void onPause() {
		super.onPause();
		
		if (CookieSyncManager.getInstance() != null) {
			CookieSyncManager.getInstance().stopSync();
		}
	}
		
 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.