Use Fragment like Activity

Overview

Fragivity : Use Fragment like Activity

English | 中文文档

JitPack Language
License

Fragivity is a library used to build APP with "Single Activity + Multi-Fragments" Architecture

  • Reasonable Lifecycle: Lifecycle is consistent with Activity when screen changed
  • Multiple LaunchModes: Supports multiple modes, such as Standard, SingleTop and SingleTask
  • Transition animation: Supports Transition or SharedElement animation when switching screens
  • Efficient communication: Simple and direct communication based on callback
  • Friendly Backpress: Supports onBackPressed interception and SwipeBack
  • Deep Links: Routes to the specified screen by URI
  • Dialog: Supports DialogFragment

Installation

JCenter is shutting down and the lib after(including) 0.2.1 can be get from JitPack.

!Note: group name changed from com.github.fragivity to com.github.vitaviva.fragivity

after 0.2.1

// add in your root build.gradle at the end of repositories
allprojects {
    repositories { 
        ...
        maven { url 'https://jitpack.io' }
    }
}
implementation 'com.github.vitaviva.fragivity:core:$latest_version'

before 0.2.0

implementation 'com.github.fragivity:core:$latest_version'

Quick start

1. declare NavHostFragment in layout

Like Navigation, Fragivity needs a NavHostFragment as the host of ChildFragments

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/nav_host"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true" />
</FrameLayout>

2. load HomeFragment in Activity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        proxyFragmentFactory()
        // with java
        // Fragivity.proxyFragmentFactory(this)

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val navHostFragment = supportFragmentManager
            .findFragmentById(R.id.nav_host) as NavHostFragment

        navHostFragment.loadRoot(HomeFragment::class)
        
        //or loadRoot with factory
        //navHostFragment.loadRoot{ HomeFragment() }

    }
}

!Note: Add proxyFragmentFactory() to ensure that the fragments can run to onStart/onStop,before super.onCreate()

3. navigate to destination Fragment

//in HomeFragment
navigator.push(DestinationFragment::class) {
    arguments = bundleOf(KEY_ARGUMENT1 to "arg1", KEY_ARGUMENT2 to "arg2")
    //or 
    applyArguments(KEY_ARGUMENT1 to "arg1", KEY_ARGUMENT2 to "arg2")
}

Launch Mode

Support multiple launch modes

navigator.push(DestinationFragment::class) {
    launchMode = LaunchMode.STANDARD //default
    //or LaunchMode.SINGLE_TOP, LaunchMode.SINGLE_TASK
}

Transition Animation

navigator.push(DestinationFragment::class) {
    //animator
    enterAnim = R.anim.slide_in
    exitAnim = R.anim.slide_out
    popEnterAnim = R.anim.slide_in_pop
    popExitAnim = R.anim.slide_out_pop
    
    //sharedElements
    sharedElements = sharedElementsOf(imageView to "id")
}

Communication

You can simply setup communication between two fragments

1. start destination Fragment with a callback

class HomeFragment : Fragment() {
    private val cb: (Int) -> Unit = { checked ->
        //...
    }

    //...

    fun startDestination() {
        navigator.push {
            DestinationFragment(cb)
        }
    }
  
    //...
}

2. callback to source Fragment

class DestinationFragment(val cb: (Int) -> Unit) : Fragment() {
    //...
    cb.invoke(xxx)
    //...
}

Show Dialog

1. declare a DialogFragment

class DialogFragment : DialogFragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val root = inflater.inflate(R.layout.fragment_dialog, container, false)
        return root
    }
}

2. show it

navigator.showDialog(DialogFragment::class)

Deep links

1. add kapt dependencies

kapt 'com.github.fragivity:processor:$latest_version'

2. declare URI with @Deeplink annotation

@DeepLink(uri = "myapp://fragitiy.github.com/")
class DeepLinkFragment : Fragment() {
    //...
}

3. handle intent in MainActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        
        //...
        
        navHostFragment.handleDeepLink(intent)

    }
}

4. start Activity with URI

val intent = Intent(Intent.ACTION_VIEW, Uri.parse("myapp://fragitiy.github.com/"))
startActivity(intent)

Router

1.composable Fragment in Activity

with(navHostFragment) {
    composable("feed") { FeedFragment.newInstance() }
    composable("search?keyword={keyword}", stringArgument("keyword")) {
        SearchFragment.newInstance()
    }
}

2.navigate to destination Fragment

navigator.push("search?keyword=$value")
// or
navigator.push("search") {
    arguments = bundleOf("keyword" to value.toString())
}

navigator.popTo("search")

Using in Java

Fragivity provides a set of APIs for Java developers

FAQ

Frequently Asked Question

License

Fragivity is licensed under the MIT License.

Comments
  • 调整显示大小,发生闪退

    调整显示大小,发生闪退

    你好,又来打扰了! 打开App后,放在后台,进设置调整显示大小后,再切回App,发生闪退, 我的demo会有这个问题, 链接 demo下载地址

    还是上次那个demo,麻烦看下,谢谢!

    08-05 21:56:13.014 22162 22162 E AndroidRuntime: FATAL EXCEPTION: main
    08-05 21:56:13.014 22162 22162 E AndroidRuntime: Process: cn.net.cloudthink.smartmirror, PID: 22162
    08-05 21:56:13.014 22162 22162 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{cn.net.cloudthink.smartmirror/cn.net.cloudthink.smartmirror.app.HasLauncherActivity}: java.lang.IllegalStateException: Restoring the Navigation back stack failed: destination 232410147 cannot be found from the current destination NavGraph(0x0) startDestination={Destination(0x31b934c) label=cn.net.cloudthink.smartmirror.app.fragment.MainFragment class=cn.net.cloudthink.smartmirror.app.fragment.MainFragment}
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3540)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3700)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:106)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:236)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:8061)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Restoring the Navigation back stack failed: destination 232410147 cannot be found from the current destination NavGraph(0x0) startDestination={Destination(0x31b934c) label=cn.net.cloudthink.smartmirror.app.fragment.MainFragment class=cn.net.cloudthink.smartmirror.app.fragment.MainFragment}
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at androidx.navigation.NavController.onGraphCreated(NavController.java:619)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at androidx.navigation.NavController.setGraph(NavController.java:592)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at androidx.navigation.NavController.setGraph(NavController.java:572)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRootInternal$FragivityUtil__ActionLoadRootKt(ActionLoadRoot.kt:89)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRoot(ActionLoadRoot.kt:53)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil.loadRoot(Unknown Source:1)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRoot(ActionLoadRoot.kt:48)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at com.github.fragivity.FragivityUtil.loadRoot(Unknown Source:1)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.net.cloudthink.smartmirror.app.HasLauncherActivity.initView(HasLauncherActivity.kt:34)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.com.broadlink.library.base.app.activity.BaseVmActivity.init(BaseVmActivity.kt:45)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.com.broadlink.library.base.app.activity.BaseVmActivity.onCreate(BaseVmActivity.kt:39)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.com.broadlink.library.base.app.activity.BaseVmDbActivity.onCreate(BaseVmDbActivity.kt:20)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at cn.net.cloudthink.smartmirror.app.HasLauncherActivity.onCreate(HasLauncherActivity.kt:25)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.Activity.performCreate(Activity.java:8127)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.Activity.performCreate(Activity.java:8098)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3513)
    08-05 21:56:13.014 22162 22162 E AndroidRuntime:        ... 11 more
    
    bug 
    opened by julystars 6
  • [IllegalStateException] Fragment xxx not associated with a fragment manager.

    [IllegalStateException] Fragment xxx not associated with a fragment manager.

    0.2.9版本 fragment流程 A -> B , B ->C, C(popSelf) -> D, D(pop) 回到B, 再从B(pop) 回到A必现闪退 0.2.5版本没有这个问题,由于出现了issue #43 一样的crash,所以升级了版本

    07-12 14:33:22.877  3072  3072 E AndroidRuntime: FATAL EXCEPTION: main
    07-12 14:33:22.877  3072  3072 E AndroidRuntime: Process: cn.net.cloudthink.smartmirror, PID: 3072
    07-12 14:33:22.877  3072  3072 E AndroidRuntime: java.lang.IllegalStateException: Fragment FamilyFragment{fc108d} (ce6e6caa-fe6c-4dae-a966-eabbe8954140) not associated with a fragment manager.
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at androidx.fragment.app.Fragment.getParentFragmentManager(Fragment.java:1040)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at androidx.navigation.fragment.NavHostFragment.findNavController(NavHostFragment.java:109)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at androidx.navigation.fragment.FragmentKt.findNavController(Fragment.kt:29)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at com.github.fragivity.LifecycleKt.getNavigator(Lifecycle.kt:20)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at cn.com.broadlink.smartscreen.common.base.BaseFragment$onResume$2.onClick(BaseFragment.kt:90)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at cn.com.broadlink.library.base.ext.binding.ViewClickAdapterKt$clickWithTrigger$1.onClick(ViewClickAdapter.kt:94)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at android.view.View.performClick(View.java:5637)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at android.view.View$PerformClick.run(View.java:22445)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:755)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:95)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:154)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6121)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
    07-12 14:33:22.877  3072  3072 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
    
    opened by julystars 6
  • 最低版本兼容问题

    最低版本兼容问题

    1.能否调整最低版本兼容。该库的最低版本为5.0 应该是为了sharedElements的过渡动画 只能在5.0以上使用,那么能不能支持4.0或4.4版本呢? 写了sharedElements 但是低于5.0版本的 不使用动画 这样可以吗? 我们的项最低版本是4.4的.

    2.popSelf的动画不顺畅 能不能设置为启动新页面之后,当前页面默默关闭,而不是先关闭再开启 ,这样动画感觉有点奇怪

    opened by newkicode 6
  • 添加简单的路由跳转功能

    添加简单的路由跳转功能

    // 绑定
     with(navHostFragment.navController) {
        composable("feed") { FeedFragment.newInstance() }
        composable("search?keyword={keyword}", stringArgument("keyword")) {
            SearchFragment.newInstance()
        }
    }
    
    // 跳转
    navigator.push("search?keyword=$value")
    navigator.push("search") {
        arguments = bundleOf("keyword" to value.toString())
    }
    
    // 回退
    navigator.popTo("search")
    

    我只大致测试了下,可能还会有点问题。

    opened by qdsfdhvh 5
  • 关于pushWithPop的支持

    关于pushWithPop的支持

    1.关于pushWithPop字面意思,能实现开启二级页面并关闭一级页面吗? root的fragment能支持pushWithPop吗? 2.关于DeekLink的跳转 现在的逻辑是跳转到这个Fragment了 但是此Activity会默认加载它的root fragment ,这个root fragment可能不是我想要加载的。可以DeekLink跳转到的目的Fragment作为root吗?或者可选是否需要默认的root fragment

    enhancement 
    opened by newkicode 3
  • 关于popSelf跳转界面和替换根布局的问题

    关于popSelf跳转界面和替换根布局的问题

    1、使用popSelf跳转界面后使用手机物理键还能返回上一级 Fragivity.of(this).pushTo(LoginFragment.class, new NavOptionsBuilder().popSelf(true).build());

    2、如何替换根布局?比如说A界面是根布局,从A界面跳转到B界面,此时B界面操作退出登录,那么跳转到登录界面C,这时候如何清掉A界面和B界面并且把C界面设为根布局?因为退出登录后就不能再返回主界面了此时栈列应该只有C界面一个Fragment

    opened by Fomovet 2
  • 关于Activity重建时异常闪退问题

    关于Activity重建时异常闪退问题

    版本: 0.2.9

    复现Demo地址:https://github.com/Fomovet/MyApplication

    问题描述:App运行后去修改xml界面中的文字,再使用Android Studio的Apply Changes Restart Activity重建预览时会出现异常闪退

    2021-08-06 00:43:38.225 26009-26009/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.myapplication, PID: 26009
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.IllegalStateException: Restoring the Navigation back stack failed: destination 112561190 cannot be found from the current destination NavGraph(0x0) startDestination={Destination(0x38d121c) label=com.example.myapplication.HomeFragment class=com.example.myapplication.HomeFragment}
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3318)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3429)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5481)
            at android.app.ActivityThread.-wrap19(Unknown Source:0)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2015)
            at android.os.Handler.dispatchMessage(Handler.java:109)
            at android.os.Looper.loop(Looper.java:166)
            at android.app.ActivityThread.main(ActivityThread.java:7555)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
         Caused by: java.lang.IllegalStateException: Restoring the Navigation back stack failed: destination 112561190 cannot be found from the current destination NavGraph(0x0) startDestination={Destination(0x38d121c) label=com.example.myapplication.HomeFragment class=com.example.myapplication.HomeFragment}
            at androidx.navigation.NavController.onGraphCreated(NavController.java:619)
            at androidx.navigation.NavController.setGraph(NavController.java:592)
            at androidx.navigation.NavController.setGraph(NavController.java:572)
            at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRootInternal$FragivityUtil__ActionLoadRootKt(ActionLoadRoot.kt:89)
            at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRoot(ActionLoadRoot.kt:53)
            at com.github.fragivity.FragivityUtil.loadRoot(Unknown Source:1)
            at com.github.fragivity.FragivityUtil__ActionLoadRootKt.loadRoot(ActionLoadRoot.kt:48)
            at com.github.fragivity.FragivityUtil.loadRoot(Unknown Source:1)
            at com.github.fragivity.Fragivity.loadRoot(Fragivity.kt:17)
            at com.example.myapplication.MainActivity.onCreate(MainActivity.java:20)
            at android.app.Activity.performCreate(Activity.java:7343)
            at android.app.Activity.performCreate(Activity.java:7333)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3271)
    
    bug 
    opened by Fomovet 2
  •  java.lang.NoSuchMethodError: No virtual method setSavedStateProvider

    java.lang.NoSuchMethodError: No virtual method setSavedStateProvider

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.guadou.kt_demo/com.guadou.kt_demo.demo.demo11_fragment_navigation.Demo11Activity}: java.lang.RuntimeException: An exception happened in constructor of class com.github.fragivity.MyViewModel at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3773) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3952) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:213) at android.app.ActivityThread.main(ActivityThread.java:8169) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) Caused by: java.lang.RuntimeException: An exception happened in constructor of class com.github.fragivity.MyViewModel at androidx.lifecycle.SavedStateViewModelFactory.create(SavedStateViewModelFactory.java:126) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) at com.github.fragivity.FragivityUtil.loadRoot(Ext.kt:97) at com.guadou.kt_demo.demo.demo11_fragment_navigation.Demo11Activity.init(Demo11Activity.kt:32) at com.guadou.lib_baselib.base.activity.AbsActivity.onCreate(AbsActivity.kt:108) at android.app.Activity.performCreate(Activity.java:8086) at android.app.Activity.performCreate(Activity.java:8074) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3746) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3952)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:213)  at android.app.ActivityThread.main(ActivityThread.java:8169)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)  Caused by: java.lang.NoSuchMethodError: No virtual method setSavedStateProvider(Ljava/lang/String;Landroidx/savedstate/SavedStateRegistry$SavedStateProvider;)V in class Landroidx/lifecycle/SavedStateHandle; or its super classes (declaration of 'androidx.lifecycle.SavedStateHandle' appears in /data/app/com.guadou.kt_demo-eTQZfjBkcRgOq7DciVaGbg==/base.apk) at com.github.fragivity.MyViewModel.(MyViewModel.kt:41) at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at androidx.lifecycle.SavedStateViewModelFactory.create(SavedStateViewModelFactory.java:116) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185)  at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)  at com.github.fragivity.FragivityUtil.loadRoot(Ext.kt:97)  at com.guadou.kt_demo.demo.demo11_fragment_navigation.Demo11Activity.init(Demo11Activity.kt:32)  at com.guadou.lib_baselib.base.activity.AbsActivity.onCreate(AbsActivity.kt:108)  at android.app.Activity.performCreate(Activity.java:8086)  at android.app.Activity.performCreate(Activity.java:8074)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3746)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3952)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:213)  at android.app.ActivityThread.main(ActivityThread.java:8169)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) 

    升级到0.1.4 或者0.1.5就会报错 0.1.3可以正常使用

    Originally posted by @liukai2530533 in https://github.com/vitaviva/fragivity/issues/5#issuecomment-773082896

    bug 
    opened by vitaviva 2
  • 0.2.4构造方法传参的问题

    0.2.4构造方法传参的问题

    之前的版本没问题 升级到0.2.4版本之后我发现通过构造方法传参会被保存下来 比如点击News列表进入详情 点击第一条News进入NewsDetail ,然后我退出页面 再点第二条News 但是获取到的id还是第一条的id 。 我之前是可以通过构造传参的 现在是不支持了吗?如果要改动那工程量好大

    bug 
    opened by newkicode 1
  • Add fragment 性能问题

    Add fragment 性能问题

    使用add fragment 的方式添加fragment ,会存在一个问题,就是activity 在后台被系统回收,然后用户从任务管理器切换到这个activity时,回退栈里所有的fragment 都会执行onCreateView,会有比较严重的性能问题。

    使用横竖屏切换demo,从日志上也可以得到验证 image

    enhancement 
    opened by Xigong93 1
  • 当升级为 navigation-fragment-ktx:2.4.0 和 androidx.navigation:navigation-ui-ktx:2.4.0 时跳转报错

    当升级为 navigation-fragment-ktx:2.4.0 和 androidx.navigation:navigation-ui-ktx:2.4.0 时跳转报错

    大佬: 你好, 如标题所示,当升级到 2.4.0时跳转会报如下错误: java.lang.NoSuchMethodError: No virtual method moveToState(Landroidx/fragment/app/Fragment;I)V in class Landroidx/fragment/app/FragmentManager; or its super classes (declaration of 'androidx.fragment.app.FragmentManager' appears in /data/app/com.xxx.xxx.xxx-J5OaT2ltiNeEvbQmx-JqVg==/base.apk) at androidx.fragment.app.FragivityFragmentNavigator.init$lambda-0(FragivityFragmentNavigator.kt:40) at androidx.fragment.app.FragivityFragmentNavigator.$r8$lambda$lP8qpNsgnLRTRz8pL1NGjhIp6Ww(Unknown Source:0) at androidx.fragment.app.FragivityFragmentNavigator$$ExternalSyntheticLambda0.onBackStackChanged(Unknown Source:2) at androidx.fragment.app.FragmentManager.reportBackStackChanged(FragmentManager.java:2030) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1865) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1764) at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701) at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:488) at android.os.Handler.handleCallback(Handler.java:900) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8668) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

    我的跳转代码如下: navigator.push(JuniorGeometryStudyFragment::class){ applySlideInOut() }

    我测试了多次,错误信息只能如上, 请大佬看看具体是什么原因造成的. 我的QQ: 712952521 PS: 我使用 com.github.vitaviva.fragivity:core:0.3.1 , navigation-fragment2个库 2.3.5, 则表现是正常的

    opened by Jooyer 2
  •  0.3.1 版本 navigator.push 携带参数并设置 popSelf = true 会闪退

    0.3.1 版本 navigator.push 携带参数并设置 popSelf = true 会闪退

    java.lang.NoSuchFieldError: No field mBackStack of type Ljava/util/Deque; in class Landroidx/navigation/NavController; or its superclasses (declaration of 'androidx.navigation.NavController' appears in /data/app/com.whitewolfx.tools-2/base.apk:classes21.dex)
            at androidx.navigation.ExtKt.removeLastBackStackEntry(Ext.kt:20)
            at com.github.fragivity.FragivityUtil__ActionPushKt.pushInternal$FragivityUtil__ActionPushKt(ActionPush.kt:80)
            at com.github.fragivity.FragivityUtil__ActionPushKt.pushInternal$FragivityUtil__ActionPushKt$default(ActionPush.kt:63)
            at com.github.fragivity.FragivityUtil__ActionPushKt.push(ActionPush.kt:39)
            at com.github.fragivity.FragivityUtil.push(Unknown Source)
            at com.github.fragivity.FragivityUtil__ActionPushKt.push(ActionPush.kt:31)
            at com.github.fragivity.FragivityUtil.push(Unknown Source)
    
    bug 
    opened by jarryleo 1
  • 采用 CallBack 构造Fragment的时候 切换动画无效

    采用 CallBack 构造Fragment的时候 切换动画无效

    官方Demo中 CheckListFragment 中 加入切换页面的动画,发现无效果 private val _adapter by lazy { CheckListAdapter { id, checked -> navigator.push { navOptions { navOptions().applySlideInOut() } CheckItemFragment(id, checked, _cb) } } }

    opened by showwiki 3
  • 关于类似自定义抽屉式菜单或者底部菜单的多个顶层导航的功能无法实现

    关于类似自定义抽屉式菜单或者底部菜单的多个顶层导航的功能无法实现

    从Navigation过来的,项目迁移,遇到一个问题,关于自定义的抽屉菜单无法配合使用多顶层导航实现Fragment之间的管理 见:官方的抽屉式多顶层导航实现示例代码

    起因是这样,因为项目使用了自定义布局的抽屉式写法类似(利用DrawerLayout实现自定义左右抽屉布局)

    但是这样在放弃使用官方样式的同时也抛弃了NavigationView的使用和menu相关的配置 所以没办法通过Navigation去实现同时多个顶层导航, 然后看了下fragivity的示例代码, 发现在Activity中去通过loadRoot()方法设置好像也只可能有一个顶层导航, 所以希望大佬看看有没有实现的可能, 如果有的话,可以麻烦在代码中加上相关示例吗? 因为我认为这是一个强需求

    enhancement 
    opened by AnthonyCoder 4
  • 集成文档缺少调用proxyFragmentFactory的说明,另外这个Java的API建议统一封装到Fragivity类里

    集成文档缺少调用proxyFragmentFactory的说明,另外这个Java的API建议统一封装到Fragivity类里

    1. 缺少文档

    override fun onCreate(savedInstanceState: Bundle?) {
            proxyFragmentFactory()
    

    在Activity创建之前,有一个proxyFragmentFactory()操作需要执行,否则A->B的时候,A Fragment的onStop/onPause的生命周期不会走,这部分文档上没有写。

    1. 建议统一封装到Fragivity类里

    现在在ReportHelper上,找了半天,看能否统一封装到Fragivity里面,并且补充文档。

    opened by caojing35 0
Releases(0.3.1)
Owner
fundroid
字节跳动内推(校招/社招/实习) | 微信13913365856 | 欢迎关注公众号「AndroidPub」
fundroid
A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

Kaustubh Patange 88 Dec 11, 2022
Android Navigation Fragment Share Element Example: Use Share Element Transition with recyclerView Item and ViewPager2 Item.

Android-Navigation-Fragment-Share-Element-Example 说明 Android 使用Navigation导航切换Fragment中使用共享元素过渡动画的例子:将在listFragment的RecyclerView的Item共享元素过渡到pagerFragme

null 3 Sep 28, 2022
Memory efficient android library for managing individual fragment backstack.

fragstack : Android library for managing individual fragment backstack. An Easy to use library for managing individual fragment back stack as Instagra

Abhishesh 21 Feb 6, 2021
Tugas Fragment Codelab Navigation Pemrograman Mobile

AndroidTrivia - starter code Starter code for Android Kotlin Fundamentals codelab 3.1: Create and add a fragment. Introduction The AndroidTrivia app a

null 0 Nov 3, 2021
BubbleTabBar is bottom navigation bar with customizable bubble like tabs

BubbleTabBar BubbleTabBar is bottom navigation bar with customizable bubble like tabs Usage <com.fxn.BubbleTabBar android:id="@+id/

Akshay sharma 576 Dec 30, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 27, 2022
The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

MaterialDrawer ... the flexible, easy to use, all in one drawer library for your Android project. What's included ?? • Setup ??️ • Migration Guide ??

Mike Penz 11.6k Dec 27, 2022
A flexible, easy to use, unique drawer library for your Android project.

Duo Navigation Drawer This Android library provides an easy way to create an alternative navigation drawer for android. Instead of a drawer that slide

PSD 1.1k Dec 21, 2022
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

AnimatedBottomBar A customizable and easy to use bottom bar view with sleek animations. Examples Playground app Download the playground app from Googl

Joery 1.2k Dec 30, 2022
A sleek, out of the box, easy to understand and use, swipe gesture based Navigational Library for android.

Facilis Swipe gesture based navigational library for Android. Watch Demo Video: Getting Started To get this project into your build: Gradle Add it in

Prem Suman 35 Feb 15, 2022
DSC Moi University session on using Navigation components to simplify creating navigation flow in our apps to use best practices recommended by the Google Android Team

Navigation Components Navigate between destination using safe args How to use the navigation graph and editor How send data between destinations Demo

Breens Mbaka 6 Feb 3, 2022
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

Joery Droppers 1000 Dec 5, 2021
A library that you can use for bottom navigation bar. Written with Jetpack Compose

FancyBottomNavigationBar A library that you can use for bottom navigation bar. W

Alperen Çevlik 3 Jul 27, 2022
NavigationAndFragments - A use case for fragments and navigation

NavigationAndFragments A use case for fragments and navigation. To implement this use case, follow these steps : Create a new fragment navigation xml

Google Developers 3 Sep 15, 2022
Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps

Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps. The extension provides handy methods and properties to change the behaviour as well as the appearance of the navigation bar.

Zain Ul Hassan 4 Nov 30, 2022
Alert Dialog - You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment.

We show a warning message (Alert Dialog) to the user in many parts of our applications. You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment. Thanks to this extension, you can create a Dialog and call it in the Activity or Fragment you want and customize the component you want.

Gökmen Bayram 0 Jan 9, 2022
Simple tool which help you to implement activity and fragment transition for pre-Lollipop devices.

PreLollipopTransition Simple tool which help you to implement activity and fragment transition for pre-Lollipop devices. Download In your app build.gr

Takahiro Menju 1.3k Nov 28, 2022
Simple event library to communicate between Activity/Fragment and ViewModel

Setup dependencies { implementation "com.github.skgmn:viewmodelevent:1.1.0" } If you don't know how to access to GitHub Packges, please refer to

null 4 Apr 6, 2022
AndroidBriefActions - Android library for sending and observing non persistent actions such as showing a message; nice readable way to call navigation actions from ViewModel or Activity/Fragment.

implementation "com.vladmarkovic.briefactions:briefactions:$briefActionsVersion" Benefits Why use brief-actions library pattern: Prevent short-term ac

null 2 Dec 22, 2022
Navigation in Android: Activity, Fragment, Intents, Navigation Component.

Words App This folder contains the source code for the Words app codelab. Introduction Words app allows you to select a letter and use Intents to navi

Shaima Alghamdi 2 Aug 15, 2022