【问题标题】:In Android, is it poor design to navigate to an Activity using nav_graph in contrast to using intents?In Android, is it poor design to navigate to an Activity using nav_graph in contrast to using intents?
【发布时间】:2022-12-27 21:52:08
【问题描述】:

I am trying to navigate back to the login activity after a sign out or deleting a user. Is there a better approach between using intents or using the nav_graph. The pros of the nav_graph is more easily managed navigation code, but how about using intents?

<action
            android:id="@+id/action_editProfile_to_loginActivity"
            app:destination="@id/loginActivity"
            app:launchSingleTop="false"
            app:popUpToInclusive="true" />

Opposed to something alike:

val intentCreateProfile = Intent(this@ActivityPhoneAuthentification, ActivityCreateProfile::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_CLEAR_TOP)
        startActivity(intentCreateProfile)
        finish()

【问题讨论】:

  • It is only very recently that the nav graph even supports navigating to activities. So it is too early for a convention or general best practice to have emerged.

标签: android kotlin


【解决方案1】:

As far as I know - it seems ok, as long as you can send/access all the things in navgraph comparing to intents...

【讨论】:

    猜你喜欢
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2022-12-02
    • 2022-12-01
    • 1970-01-01
    • 2022-12-26
    • 2022-12-28
    相关资源
    最近更新 更多