How do I set the parent activity of an activity at runtime?

前端 未结 1 957
野性不改
野性不改 2021-01-18 10:57

I have an arbitrary number of hierarchically nested views/activities. The action bar should show the Up navigation button to navigate to a higher level in any view. For this

相关标签:
1条回答
  • It sounds like you are confusing up and back navigation.

    The up button should be deterministic. From a given screen, the up button should always bring the user to the same screen.

    The back button should not always bring the user to the same screen. The purpose of the back button is to help the user go backwards through your app chronologically. It should bring the user to the previous screen.

    If there is no clear hierarchy of screens (e.g. there are no parent/child screens), then you may not need to implement up navigation at all.

    See: Navigation with Up and Back

    One option for overriding the default up button behavior is to simply intercept up button clicks and handle it yourself. For example:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            // Launch the correct Activity here
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    0 讨论(0)
提交回复
热议问题