티스토리 뷰

Mobile/Android

[Android]UpNavigation 구현

out of coding 2015. 9. 8. 16:15

안드로이드 ActionBar의 상단에 백버튼을 누르면

하단의 백버튼과는 다르게 동작을 하게 되어 있다.


구현은 다음과 같이...

 @Override

public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case android.R.id.home:

        Intent upIntent = NavUtils.getParentActivityIntent(this);

        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {

            // This activity is NOT part of this app's task, so create a new task

            // when navigating up, with a synthesized back stack.

            TaskStackBuilder.create(this)

                    // Add all of this activity's parents to the back stack

                    .addNextIntentWithParentStack(upIntent)

                    // Navigate up to the closest parent

                    .startActivities();

        } else {

            // This activity is part of this app's task, so simply

            // navigate up to the logical parent activity.

            NavUtils.navigateUpTo(this, upIntent);

        }

        return true;

    }

    return super.onOptionsItemSelected(item);

}

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함