¾È±Ô °øºÎ¹æ

Android > Thread Message Àü´Þ ¹æ¹ý

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

¾ÖÇø®ÄÉÀ̼ÇÀ» À§ÇØ ÇÁ·Î°Ô½º°¡ ¸¸µé¾î Áö¸é ¸ÞÀνº·¹µå´Â ÃÖ»óÀ§¿¡¼­ °ü¸®µÇ´Â ¾ÖÇø®ÄÉÀÌ¼Ç °´Ã¼ÀÎ ¾ÖƼºñƼ,

ºê·Îµåij½ºÆ® ¼ö½ÅÀÚ µî°ú »õ·Î¸¸µé¾îÁö´Â À§µµ¿ì¸¦ °ü¸®Çϱâ À§ÇÑ ¸Þ½ÃÁö Å¥¸¦ ½ÇÇàÇÏ°Ô µË´Ï´Ù.

ÀÌ ¸Þ½ÃÁö Å¥¸¦ ÀÌ¿ëÇØ ¼øÂ÷ÀûÀ¸·Î Äڵ带 ¼öÇàÇÒ ¼ö ÀÖÀ¸¸ç ÀÌ ¸Þ½ÃÁö Å¥¸¦ ÀÌ¿ëÇØ ¸ÞÀÎ ½º·¹µå¿¡¼­ ó¸®ÇÒ ¸Þ½ÃÁö¸¦ Àü´ÞÇÏ´Â

¿ªÇÒÀ» ´ã´çÇÏ´Â °ÍÀÌ Çڵ鷯 Ŭ·¡½º ÀÔ´Ï´Ù.

Thead ¿Í Çڵ鷯¼öÇà¼ø¼­

1. Çڵ鷯°¡ °ü¸®ÇÏ´Â ¸Þ½ÃÁö Å¥¿¡¼­ ó¸®ÇÒ ¼ö ÀÖ´Â ¸Þ½ÃÁö °´Ã¼ Çϳª¸¦ ÂüÁ¶ÇÑ´Ù.
2. obtainMessage() ¸¦ ÀÌ¿ëÇØ È£ÃâÀÇ°á°ú·Î ¸Þ½ÃÁö °´Ã¼¸¦ ¸®ÅϹ޴´Ù.
3. ¸Þ¼¼Áö °´Ã¼¿¡ Á¤º¸¸¦ ³Ö´Â´Ù.
4. sendMessage() ¸Þ¼Òµå¸¦ ÀÌ¿ëÇØ ¸Þ½ÃÁö Å¥¿¡ ³Ö´Â´Ù.
5. handleMessage() ¸Þ¼Òµå¿¡ Á¤ÀÇµÈ ±â´ÉÀÌ ¼öÇàµÈ´Ù.

À§ÀÇ °úÁ¤À» ±¸Ã¼ÀûÀÎ ÄÚµå·Î »ìÆ캸ÀÚ.

 
	public class test extends Activity {
		public void onCreate(Bundle savedInstanceState) {
			ProgressHandler  handler;
			handler = new ProgressHandler();

			Thread thread1 = new Thread(new Runnable() {
				public void run() 
				{
					Message msg = handler.obtainMessage();	//È£ÃâÀÇ°á°ú·Î ¸Þ½ÃÁö °´Ã¼¸¦ ¸®ÅϹ޴´Ù.
					msg.what	= 1;
					msg.id	= "abc";
					handler.sendMessage(msg);			//msg ¸¦ ProgressHandler Ŭ·¡½ºÀÇ handleMessage·Î Àü¼ÛÇÑ´Ù.
				}
			});

			thread1.start();
	  }

		public class ProgressHandler extends Handler {
			public void handleMessage(Message msg) {
				
				//¹ÞÀº ¸Þ½ÃÁö¸¦ ó¸®ÇÑ´Ù.

				Int str1= (String)msg.what;
				String str2 = (String)msg.id;	       
				Log.e("SampleJavaThread","Exception in thread.",str2);

			}
		}
	}


¼öÇà¼ø¼­¿Í ¾Æ·¡ ¼Ò½º¸¦ º¸°í ºÐ¼®ÇØ º¸±â ¹Ù¶õ´Ù.
 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.