Back Navigation for ActionBar on Android

AndroidManifest.xml

        <activity android:name=".ProfileActivity">
            <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MainActivity"/>
        </activity>

ProfileActivity.java

public class ProfileActivity extends AppCompatActivity {

    Toolbar toolbarProfile;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);

        toolbarProfile = (Toolbar) findViewById(R.id.toolbarProfile);
        setSupportActionBar(toolbarProfile);
        ViewCompat.setLayoutDirection(toolbarProfile, ViewCompat.LAYOUT_DIRECTION_RTL);
        getSupportActionBar().setTitle(R.string.profile_management);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_back); // for custom indicator
        
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // Respond to the action bar's Up/Home button
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                //Intent intent=new Intent(ProfileActivity.this,MainActivity.class);
                //NavUtils.navigateUpTo(ProfileActivity.this,intent);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {

        NavUtils.navigateUpFromSameTask(this);

        super.onBackPressed();
    }
}

References
https://developer.android.com/training/implementing-navigation/ancestral.html
https://developer.android.com/training/implementing-navigation/temporal.html
https://stackoverflow.com/questions/28740610/how-do-i-show-back-button-in-activity
https://stackoverflow.com/questions/5312334/how-to-handle-back-button-in-activity