한국어

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();
}
번호
제목
글쓴이
96 [Android] 배터리 최적화 대응하기: 도즈(Doze)와 어플 대기모드(App Standby)
admin
25416   2018-01-02
 
안드로이드 백 뒤로가기 버튼 back button of action bar in Android
admin
21197   2018-12-24
https://stackoverflow.com/questions/36457564/display-back-button-of-action-bar-is-not-going-back-in-android/36457747 Display back button of action bar is not going back in AndroidAsk Question 6 4 I am developing an An...  
94 8.0 부터는 Notification Channel을 만들어 주기 하지 않으면 알림이 오지 않는다
admin
18996   2018-05-11
 
93 Runtime Permissions in Android Marshmallow 6.0 and above
admin
18701   2018-12-05
 
92 안드로이드 앱 배터리 최적화 무시방법
admin
17540   2018-01-02
 
91 Firebase Console의 Notification google android 구글 안드로이드 푸시
admin
17304   2018-01-04
 
90 설정값 유지하기 ( SharedPreferences ) 쉽고 잘된설명
admin
17243   2018-03-22
 
89 Oreo 버전 이후 Foreground Service 사용 방법
admin
16736   2018-12-22
 
88 새로운 안드로이드 백그라운드 작업 처리법 : WorkManager
admin
16471   2018-11-25
 
87 알림 애플리케이션의 정상 UI 외부에서 사용자에게 표시
admin
15664   2018-01-05
 
86 Service와 BroadcastReceiver로 스크린 화면 감지하기
admin
15586   2018-01-07
 
85 SMS 또는 통화 기록 사용 위험도 가 높거나 민감한 권한을 사용하는 것을 제한
admin
15397   2018-11-18
 
84 Doze 및 앱 대기 모드 최적화
admin
15366   2018-01-01
 
83 @Deprecated @Override 라는 어노테이션 사용 설명
admin
15359   2018-06-16
 
82 In favour of overriding onNewToken FirebaseMessagingService
admin
15218   2018-12-22
 
81 FCM 과 GCM 차이
admin
15133   2018-01-01
 
80 Play Store to require new and updated apps to target recent API levels and distribute native apps with 64-bit support
admin
15054   2018-05-13
 
79 안드로이드 OREO 백그라운드 서비스 제한 대책
admin
14986   2018-12-22
 
78 Notification 을 사용 알림 지워지지 않고 여러개 표시 되게 하는 방법
admin
14885   2018-05-11
 
77 동작 변경사항: API 레벨 28+를 대상으로 하는 앱 Android Pie
admin
14840   2018-12-22
 
76 안드로이드 개발자 개발 프로그램 7.0 누가 백그라운드 최적화
admin
14436   2018-01-16
 
75 Android 7.0 동작 변경 사항 밧데리 메모리 잠자기 모드
admin
14408   2018-01-02
 
74 안드로이드 마시맬로 6.0 이상의 런타임 권한
admin
14353   2018-12-05
 
73 Remote Notifications with Firebase Cloud Messaging
admin
14147   2018-01-02
 
72 Firebase FCM 강제로 onTokenRefresh () 호출 [android] 서버로 json put token 전송
admin
14091   2018-04-26
 
71 how to set CheckBoxPreference default value 체크박스 디폴트값 설정
admin
14014   2018-05-16
 
70 Android Drawable Resources Tutorial
admin
14006   2018-12-05
 
69 [안드로이드 개발자 개발 ] 기본 스레드의 생명주기 관리 자세히 알아보기
admin
13977   2018-01-16
 
68 Doze 및 앱 대기 모드 최적화 GCM으로 Android M Doze 모드를 풀기
admin
13926   2018-01-09
 
67 Migrate a GCM Client App for Android to Firebase Cloud Messaging
admin
13889   2017-12-04
 
66 unpublish an app in Google Play Developer Console 플레이스토어 앱 게시 삭제
admin
13849   2018-05-21
 
65 FCM PHP Curld
admin
13816   2018-01-01
 
64 FCM 원하는 액티비티 이름을 알림을 요청 전송하여 액티비티 열리게
admin
13814   2019-06-24
 
63 안드로이드 사용자 주소록리스트 가져오기
admin
13693   2018-06-16
 
62 System Permission MODIFY_PHONE_STATE root device
admin
13684   2018-12-08
 
61 firebase로 손쉽게 android 앱에 로그인 추가하기
admin
13601   2018-12-05
 
60 Firebase용 Cloud 함수
admin
13555   2018-04-26
 
59 how do you import sound files like mp3 or waw files into android studio?
admin
13450   2018-01-02
 
58 안드로이드 : 컨텐트 제공자 (Content Provider) 연락처 데이터 ContentResolver 객체
admin
13439   2018-11-21
 
57 sdk-tools list
admin
13439   2018-05-13
 
56 Android-Oreo-Foreground-Service-Simple-Example 쉽고 정확한설명
admin
13430   2018-12-22
 
55 Android Contact APP with RecyclerView Part 1: Call Logs Example Android Studio
admin
13288   2018-11-18
 
54 안드로이드 getDeviceId getImei MEID
admin
13265   2018-12-28
 
53 사용자는 Settings > Battery > Battery Optimization에서 수동으로 허용 과 프로그램
admin
13221   2018-01-01
 
52 WIFI_SLEEP_POLICY_NEVER how to set in API-17?
admin
13205   2018-01-02
 
51 Android 6.0(API 레벨 23)부터 사용자 런타임에 권한 요청
admin
13145   2018-12-05
 
50 Android 9 Pie 새로운기능
admin
13142   2018-12-22
 
49 Android Oreo의 알림 채널
admin
13131   2018-12-10
 
48 get path dir 함수 종합 정리
admin
13128   2018-05-25
 
47 opensips Sipdroid Push notification how to
admin
13109   2017-12-27
 
46 안드로이드 버젼 별 특징 새로운 기능
admin
13048   2018-01-02
 
45 How to initialize default preferences for Settings in Android 초기값 설정
admin
13032   2018-04-25
 
44 Gradle Wrapper를 통해 이용하기
admin
13031   2018-05-07
 
43 android 9 startForeground requires android.permission.FOREGROUND_SERVICE
admin
13028   2019-05-25
 
42 안드로이드 마쉬멜로우 버전 이상에서 권한처리하기.
admin
12961   2018-09-06
 
41 Improving app security and performance on Google Play for years to come
admin
12947   2018-05-13
 
40 How do I keep Wifi from disconnecting when phone is asleep?
admin
12938   2018-01-02
 
39 안드로이드 알람
admin
12904   2018-02-23
 
38 Uri to default sound notification?
admin
12879   2018-02-03
 
37 P is for Policy: Upcoming changes to Google Play
admin
12844   2018-05-13
 
36 안드로이드 전화 수신 발신 이력조회 CALLLOG
admin
12827   2018-09-10
 
35 Notification에 관한 설명 자세한설명
admin
12809   2019-03-01
 
34 안드로이드 android MediaPlayer how to work
admin
12808   2018-01-16
 
33 gcm 코딩 사례
admin
12793   2018-01-09
 
32 안드로이드 밧데리 전원 수명 오래쓰기 보안 최적화 끄기 끄는 방업 소개
admin
12751   2018-01-02
 
31 jobscheduler 간략하게 설명
admin
12748   2018-12-22
 
30 android apk 패키징 v1, v2
admin
12676   2018-12-05
 
29 SDK Platform Release Notes
admin
12605   2018-05-13
 
28 JobScheduler - Android Studio Tutorial
admin
12545   2018-12-22
 
27 android.os.Build.VERSION_CODES.O 오레오 알림 작성
admin
12543   2018-12-14
 
26 android.telephony.TelephonyManager.getSubscriberId 베스트코드 code
admin
12514   2018-12-31
 
25 안드로이드 스튜디오 PreferenceActivity로 설정창 쉽게 만들기
admin
12467   2020-01-17
 
24 Android Shape Drawable Examples
admin
12436   2018-12-05
 
23 Questions & Answers Android 개발자
admin
12375   2018-04-26
 
22 안드로이드 버전 역사
admin
12370   2018-09-01
 
21 Android 6.0 이상 접근권한 checkselfPermission source code
admin
12367   2018-09-06
 
20 FirebaseInstanceIdService is deprecated now FCM token
admin
12278   2019-05-29
 
19 goodbye to your implicit BroadcastReceivers
admin
12265   2018-05-01
 
18 Android sms intent filter SMS 보내기
admin
12214   2018-12-19
 
17 Android OS 9 Pie 동작 변경사항 정리 개발자용
admin
12188   2019-05-25
 
16 일반 Activity와 AppCompatActivity의 차이 ?
admin
12164   2018-12-06
 
15 안드로이드 개발시에 팩키지명 변경하기
admin
12028   2018-09-21
 
14 android.os.Build.VERSION_CODES.O 오레오 알림 작성 소스코드
admin
11992   2018-12-14
 
13 런타임 안드로이드 권한 SDK 23 이상 권한 부여하기 코드
admin
11942   2018-12-06
 
12 안드로이드 스튜디오 에서 팩키지명 변경하기 동영상 으로 보기
admin
11883   2018-10-01
 
11 안드로이드 디버깅 Logcat을 이용해서 로그 남기기
admin
11679   2019-09-18
 
10 Android Service and Jobscheduler sourcecode
admin
11674   2018-12-22
 
9 add set and cancel of the notification on those listeners
admin
11585   2018-12-14
 
8 Google wants developers to add dark themes to save battery life
admin
11533   2019-03-28
 
7 [Android] activity 인텐트(Intent) 화면 간 이동과 데이터 전달 잘된설명
admin
11297   2019-12-24
 
6 안드로이드 원그래프 걱은선그래프 만들기 그리기
admin
10962   2019-12-24
 
5 안드로이드 비동기 통신 결과값을 Textview set text 값 설정 기록 표시셋 이해 하기 쉽게
admin
10938   2019-12-17
 
4 안드로이드 웹뷰 webview 설명좀 잘해놓은곳 androidx 사용
admin
10925   2019-12-24
 
3 FCM 푸시 메세지 전송
admin
10781   2019-09-27
 
2 안드로이드 6.0 permission 가장잘된 예제
admin
10607   2019-12-12
 
1 How to fish notification enable
admin
10586   2019-10-13