我的应用程序有一个静态快捷方式,我正在使用导航架构组件。
我正在使用以下实现方法,但在Android 9上无法正常工作。
在我的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>
在调试应用程序时,我注意到调用了 findNavController(...)
方法,但屏幕上没有任何反应。
此外,我没有覆盖 onStart(...)
或 onResume(...)
方法。
是否有特定的方法可以使用导航组件实现应用程序快捷方式,或者我在这里做错了什么?
popBackStack()
是返回上一步操作 - 你是不是想调用navigate()
来进行导航呢? - ianhanniballake