![](/bink.gif) |
|
| ![](/bink.gif) |
µÚ·Î°¡±â(Back ¹öÆ°) µÎ¹ø ´·¯ ¾Û Á¾·áÇϱâ |
|
|
![](icon/private_name/1.gif) |
8³â Àü |
¿äÁò ¸¹Àº ¾îÇõéÀÌ µÚ·Î°¡±â ¹öÆ°À» µÎ¹ø ´·¯ ¾ÛÀ» Á¾·á½ÃŲ´Ù.
Á¾·áÇϽðڽÀ´Ï±î? ¶ó´Â È®ÀÎâÀÌ ¶ß°í È®ÀÎÀ» ´·¯¾ß µÇ´Â ¹ø°Å·Î¿òÀÌ ¾ø°í, À߸ø Á¾·á¹öÆ°À» ´·¶À» °æ¿ì¿¡µµ Å佺Ʈ ¾Ë¸²Ã¢¸¸ ¶ã»Ó º°´Ù¸¥ ¹æÇØ¿ä¼Ò°¡ ¾ø¾î¼ Âü ÁÁÀº°Í °°´Ù.
¿äÁò ´ëºÎºÐÀÇ ¾ÛÀÌ ÀÌ·¯ÇÑ Á¾·á ¹æ½ÄÀ» ¼±ÅÃÇÏ°í Àֱ⶧¹®¿¡ Çѹø ±¸ÇöÀ» Çغ¸ÀÚ. ±¸Çö¹æ¹ýÀº °£´ÜÇÏ´Ù µÚ·Î°¡±â ¹öÆ° Ŭ¸¯½Ã ÇöÀç½Ã°£À» ÀúÀåÇϸç Å佺Ʈ ¾Ë¸²Ã¢À» ¶ç¿öÁÖ°í Çѹø´õ ´·¶À»¶§ ÀÏÁ¤½Ã°£(¿¹¸¦µé¸é 2ÃÊ)°¡ Áö³µ´ÂÁö È®ÀÎÇÏ°í ÀÏÁ¤½Ã°£ÀÌ Áö³ªÁö ¾Ê¾ÒÀ» °æ¿ì Á¾·á, Áö³µÀ» °æ¿ì ¾Ë¸²Ã¢À» ´Ù½Ã ¶ç¿öÁÖ¸é µÈ´Ù.
1. ½Ã°£À» ÀúÀåÇÏ´Â º¯¼ö(t) = 0;
2. µÚ·Î°¡±â ¹öÆ° (óÀ½)Ŭ¸¯½Ã ½Ã°£À» ÀúÀåÇÏ´Â º¯¼ö(t) + 2000(2ÃÊ)°¡ ÇöÀç ½Ã°£º¸´Ù ÀÛ´Ù.
3-1. ¾Ë¸²Ã¢À» ¶ç¿î´Ù.('µÚ·Î'¹öÆ°À» Çѹø ´õ ´©¸£½Ã¸é Á¾·áµË´Ï´Ù.)
3-2. ½Ã°£À» ÀúÀåÇÏ´Â º¯¼ö(t)¿¡ ÇöÀç ½Ã°£À» ÀúÀåÇÑ´Ù.
4. µÚ·Î°¡±â ¹öÆ°À» Çѹø´õ Ŭ¸¯
5-1. ÇöÀç ½Ã°£ÀÌ º¯¼öt + 2000º¸´Ù ÀÛÀ¸¸é ¾Û Á¾·á
5-2. ÇöÀç ½Ã°£ÀÌ º¯¼öt + 2000º¸´Ù Å©¸é t¿¡ ÇöÀç½Ã°£À» ÀúÀåÇÏ°í ¾Ë¸²Ã¢À» ¶ç¿î´Ù.
±Û·Î º¸¸é ¾î·Æ´õ¶óµµ ¼Ò½º¸¦ º¸¸é ¾Æ¸¶ ¹Ù·Î ÀÌÇØ°¡ °¥ °ÍÀÌ´Ù. ¸ÕÀú µÚ·Î°¡±â ¹öÆ°ÀÇ À̺¥Æ®¸¦ ´ã´çÇϴ Ŭ·¡½º¸¦ Çϳª ¸¸µé¾ú´Ù.
BackPressCloseHandler.java
import android.app.Activity;
import android.widget.Toast;
public class BackPressCloseHandler {
private long backKeyPressedTime = 0;
private Toast toast;
private Activity activity;
public BackPressCloseHandler(Activity context) {
this.activity = context;
}
public void onBackPressed() {
if (System.currentTimeMillis() > backKeyPressedTime + 2000) {
backKeyPressedTime = System.currentTimeMillis();
showGuide();
return;
}
if (System.currentTimeMillis() <= backKeyPressedTime + 2000) {
activity.finish();
toast.cancel();
}
}
public void showGuide() {
toast = Toast.makeText(activity,
"\'µÚ·Î\'¹öÆ°À» Çѹø ´õ ´©¸£½Ã¸é Á¾·áµË´Ï´Ù.", Toast.LENGTH_SHORT);
toast.show();
}
}
´ÙÀ½Àº ÀÌ ±â´ÉÀ» »ç¿ëÇÏ·Á´Â ¾×ƼºñƼ¿¡¼ ³Ö¾îÁà¾ß µÇ´Â ¼Ò½ºÀÌ´Ù.
»ç¿ëÇÏ·Á´Â ¾×ƼºñƼ¿¡ onBackPressed()¸Þ¼Òµå¸¦ »ý¼ºÇÏ°í BackPressCloseHandler Ŭ·¡½ºÀÇ onBackPressed()¸Þ¼Òµå¸¦ ºÒ·¯¿ÍÁÖ¸é µÈ´Ù.
MainActivity.java
public class MainActivity extends Activity {
private BackPressCloseHandler backPressCloseHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
backPressCloseHandler = new BackPressCloseHandler(this);
}
@Override
public void onBackPressed() {
//super.onBackPressed();
backPressCloseHandler.onBackPressed();
}
}
|
|
̵̧ : 267 |
̵̧
¸ñ·Ï
|
|
| ![](/bink.gif) |
|