My app has one static shortcut, and I'm using the navigation architecture component.
I'm using the following implementation but it does not work on Android 9.
In my MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupToolbar()
setupNavigationDrawer()
checkPermissions()
if (intent.action == MoneyBook.SHORTCUT_ACTION_ADD_BOOKENTRY) {
findNavController(R.id.nav_host_fragment).popBackStack(R.id.action_entriesFragment_to_newBookEntryFragment, false)
}
}
shortcuts.xml:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/ic_shortcut_addbookentry"
android:shortcutId="shortcut_addbookentry"
android:shortcutLongLabel="@string/shortcut_addbookentry_label_short"
android:shortcutShortLabel="@string/shortcut_addbookentry_label_short">
<intent
android:action="at.guger.moneybook.action.ADD_BOOKENTRY"
android:targetClass="at.guger.moneybook.activity.MainActivity"
android:targetPackage="at.guger.moneybook.dev" />
</shortcut>
</shortcuts>
When debugging the app, I noticed that the findNavController(...)
method is called, but nothing happens on the screen.
Further, I do not override onStart(...)
or onResume(...)
.
Is there any given way to implement app shortcuts with navigation component or am I doing something terribly wrong here?
popBackStack()
goes back - do you mean to callnavigate()
instead? – Joy