Skip to content

Commit aa20d9f

Browse files
committed
More robust handling for nav controller
1 parent 4e40551 commit aa20d9f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

app/src/main/java/com/futsch1/medtimer/MainActivity.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ protected void onNewIntent(Intent intent) {
155155

156156
@Override
157157
public boolean onSupportNavigateUp() {
158-
NavController navController = findNavController(this, R.id.navHost);
159-
return NavigationUI.navigateUp(navController, appBarConfiguration)
160-
|| super.onSupportNavigateUp();
158+
try {
159+
NavController navController = findNavController(this, R.id.navHost);
160+
return NavigationUI.navigateUp(navController, appBarConfiguration)
161+
|| super.onSupportNavigateUp();
162+
} catch (IllegalStateException e) {
163+
return false;
164+
}
161165
}
162166
}

app/src/main/java/com/futsch1/medtimer/OptionsMenu.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ private static void enableOptionalIcons(@NonNull Menu menu) {
105105
private void setupSettings() {
106106
MenuItem item = menu.findItem(R.id.settings);
107107
item.setOnMenuItemClickListener(menuItem -> {
108-
Navigation.findNavController(view).navigate(R.id.action_global_preferencesFragment);
109-
return true;
108+
try {
109+
Navigation.findNavController(view).navigate(R.id.action_global_preferencesFragment);
110+
return true;
111+
} catch (IllegalStateException e) {
112+
return false;
113+
}
110114
});
111115
}
112116

0 commit comments

Comments
 (0)