There is a main activit, in it a fragment that contains a list. There is a button (if it is important, there is a custom panel below, that is, it is not in the list items and has nothing to do with the adapter).

This button calls the next activation - everything turns out as expected, except for the fact that it does not return to the main activation by the back arrow. Only and only on the back button.

Call code for the new activation:

@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(LAYOUT, container, false); setRetainInstance(true); ImageButton sort = (ImageButton) view.findViewById(R.id.sort_by); sort.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getActivity(),SortBy.class); startActivity(intent); } }); return view; } 

SortBy class:

 public class SortBy extends AppCompatActivity { private Toolbar toolbar; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sort_by_activity); setToolbar(); } private void setToolbar() { toolbar = (Toolbar) findViewById(R.id.sort_toolbar); toolbar.setTitle("Sort by"); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } 

What missed where wrong?

    1 answer 1

    If the minimum API level allows, then you can limit android:parentActivityName=".ActivityMain" to specifying android:parentActivityName=".ActivityMain" as a second activation attribute in the manifest. If it does not, then you need to add another meta-data tag inside the activation tag in the manifest:

     <!-- Parent activity meta-data to support 4.0 and lower --> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".ActivityMain" /> 

    Or hang the toolbar listener programmatically:

     toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); //или вызываем нажатие на back: onBackPressed(); } });