한국어

Coding

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

     페북공유

   ◎위챗 : speedseoul


  
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


https://stackoverflow.com/questions/36457564/display-back-button-of-action-bar-is-not-going-back-in-android/36457747


6

I am developing an Android app. I am using ActionBar with AppCompactActivity. In my app, I add back button to action bar. But when I click on it, it is not going back to the previous activity. For example, I start activity 2 from activity 1. Activity 2 contains action bar with back button. But when I click on action bar back button of activity 2, it is not going back to activity 1.

This is how I set action bar for activity 2:

public class EditProfileActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_profile);
        Toolbar toolbar = (Toolbar)findViewById(R.id.profile_action_toolbar);
        setSupportActionBar(toolbar);
        setTitle("Edit Profile");
        ActionBar actionBar= getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}

This is how I started activity 2 from activity 1:

Intent i = new Intent(MainActivity.this,SecondActivity.class);
                    startActivity(i);

It is not going back when I click this button

enter image description here

Why it is not going back?

29

Add the following to your activity.You have to handle the click event of the back button.

@Override
 public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()){
         case android.R.id.home:
              onBackPressed();
              return true;
       }
   return super.onOptionsItemSelected(item);
 }
7

Here you have 2 options:

a) provide a parentActivityName to your SecondActivity tag in AndroidManifest.xml like this:

 <activity
    ...
    android:name=".SecondActivity"
    android:parentActivityName=".MainActivity" >

b) override onOptionsItemSelected in SecondActivity like this:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        onBackPressed();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

I would suggest reading this guide for more information.

1

Here is your code

 public class EditProfileActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.edit_profile);
            Toolbar toolbar = (Toolbar)findViewById(R.id.profile_action_toolbar);
            setSupportActionBar(toolbar);
            setTitle("Edit Profile");
            ActionBar actionBar= getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            int id = item.getItemId();
            if (item.getItemId() == android.R.id.home) {
                   finish();
            }

            return super.onOptionsItemSelected(item);
        }
    }     
0

You have to override onOptionsItemSelected and check the item's id, if it is equals with home button's id, just call onBackPressed method.

@Override
        public boolean onOptionsItemSelected(MenuItem item) {
            if (item.getItemId() == android.R.id.home) {
                onBackPressed();
            }
            return super.onOptionsItemSelected(item);
        }
0

You have to define what should happen when you click on that button, this can be done in your second activity's onOptionsItemSelected method. Notice the android.R.id.home constant which refers to the activity's back button that you want to use.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case android.R.id.home:

        finish(); //close the activty
        return true;
    }
    return super.onOptionsItemSelected(item);
}
-1

First of all, always see Android Guidelines http://developer.android.com/intl/pt-br/design/patterns/navigation.html to prevent Google blocks Android apps.

Try to add this code in your Activity

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
        case android.R.id.home:
            onBackPressed();
            break;
    }

    return super.onOptionsItemSelected(menuItem);
}

@Override
public void onBackPressed() {
    super.onBackPressed();
}
번호
제목
글쓴이
안드로이드 백 뒤로가기 버튼 back button of action bar in Android
admin
2018-12-24 33246
54 Runtime Permissions in Android Marshmallow 6.0 and above
admin
2018-12-05 30406
53 Oreo 버전 이후 Foreground Service 사용 방법
admin
2018-12-22 29072
52 새로운 안드로이드 백그라운드 작업 처리법 : WorkManager
admin
2018-11-25 28339
51 In favour of overriding onNewToken FirebaseMessagingService
admin
2018-12-22 27791
50 SMS 또는 통화 기록 사용 위험도 가 높거나 민감한 권한을 사용하는 것을 제한
admin
2018-11-18 27660
49 동작 변경사항: API 레벨 28+를 대상으로 하는 앱 Android Pie
admin
2018-12-22 27217
48 안드로이드 OREO 백그라운드 서비스 제한 대책
admin
2018-12-22 26932
47 @Deprecated @Override 라는 어노테이션 사용 설명
admin
2018-06-16 26610
46 firebase로 손쉽게 android 앱에 로그인 추가하기
admin
2018-12-05 25951
45 Android Contact APP with RecyclerView Part 1: Call Logs Example Android Studio
admin
2018-11-18 25829
44 Notification에 관한 설명 자세한설명
admin
2019-03-01 25759
43 안드로이드 사용자 주소록리스트 가져오기
admin
2018-06-16 25658
42 Android sms intent filter SMS 보내기
admin
2018-12-19 25638
41 안드로이드 getDeviceId getImei MEID
admin
2018-12-28 25479
40 안드로이드 마시맬로 6.0 이상의 런타임 권한
admin
2018-12-05 25351
39 Android Drawable Resources Tutorial
admin
2018-12-05 25308
38 Android 9 Pie 새로운기능
admin
2018-12-22 25234
37 JobScheduler - Android Studio Tutorial
admin
2018-12-22 25096
36 안드로이드 전화 수신 발신 이력조회 CALLLOG
admin
2018-09-10 24989
35 Android Oreo의 알림 채널
admin
2018-12-10 24871
34 Android 6.0(API 레벨 23)부터 사용자 런타임에 권한 요청
admin
2018-12-05 24789
33 unpublish an app in Google Play Developer Console 플레이스토어 앱 게시 삭제
admin
2018-05-21 24754
32 안드로이드 개발시에 팩키지명 변경하기
admin
2018-09-21 24752
31 android.telephony.TelephonyManager.getSubscriberId 베스트코드 code
admin
2018-12-31 24607
30 android.os.Build.VERSION_CODES.O 오레오 알림 작성
admin
2018-12-14 24573
29 안드로이드 : 컨텐트 제공자 (Content Provider) 연락처 데이터 ContentResolver 객체
admin
2018-11-21 24568
28 일반 Activity와 AppCompatActivity의 차이 ?
admin
2018-12-06 24548
27 Android OS 9 Pie 동작 변경사항 정리 개발자용
admin
2019-05-25 24510
26 FCM 원하는 액티비티 이름을 알림을 요청 전송하여 액티비티 열리게
admin
2019-06-24 24502
25 Android 6.0 이상 접근권한 checkselfPermission source code
admin
2018-09-06 24487
24 get path dir 함수 종합 정리
admin
2018-05-25 24445
23 안드로이드 버전 역사
admin
2018-09-01 24289
22 안드로이드 스튜디오 PreferenceActivity로 설정창 쉽게 만들기
admin
2020-01-17 24125
21 안드로이드 스튜디오 에서 팩키지명 변경하기 동영상 으로 보기
admin
2018-10-01 24103
20 android 9 startForeground requires android.permission.FOREGROUND_SERVICE
admin
2019-05-25 24067
19 jobscheduler 간략하게 설명
admin
2018-12-22 23839
18 System Permission MODIFY_PHONE_STATE root device
admin
2018-12-08 23696
17 FirebaseInstanceIdService is deprecated now FCM token
admin
2019-05-29 23622
16 android apk 패키징 v1, v2
admin
2018-12-05 23520
15 런타임 안드로이드 권한 SDK 23 이상 권한 부여하기 코드
admin
2018-12-06 23458
14 안드로이드 웹뷰 webview 설명좀 잘해놓은곳 androidx 사용
admin
2019-12-24 23430
13 안드로이드 디버깅 Logcat을 이용해서 로그 남기기
admin
2019-09-18 23385
12 Android Shape Drawable Examples
admin
2018-12-05 23328
11 안드로이드 마쉬멜로우 버전 이상에서 권한처리하기.
admin
2018-09-06 23227
10 Android Service and Jobscheduler sourcecode
admin
2018-12-22 23132
9 안드로이드 원그래프 걱은선그래프 만들기 그리기
admin
2019-12-24 23030
8 android.os.Build.VERSION_CODES.O 오레오 알림 작성 소스코드
admin
2018-12-14 22820
7 Google wants developers to add dark themes to save battery life
admin
2019-03-28 22525
6 [Android] activity 인텐트(Intent) 화면 간 이동과 데이터 전달 잘된설명
admin
2019-12-24 22512
5 안드로이드 비동기 통신 결과값을 Textview set text 값 설정 기록 표시셋 이해 하기 쉽게
admin
2019-12-17 22385
4 안드로이드 6.0 permission 가장잘된 예제
admin
2019-12-12 22013
3 How to fish notification enable
admin
2019-10-13 21903
2 add set and cancel of the notification on those listeners
admin
2018-12-14 21859
1 FCM 푸시 메세지 전송
admin
2019-09-27 21654