首页 > 解决方案 > 从 FileObserver 服务启动片段

问题描述

我需要从 FileObserver 服务打开一个片段。我尝试这样,但它不起作用

MyFragment newFragmentTop = new MyFragment();
        getActivity().getSupportFragmentManager().beginTransaction()
                .add(R.id.container, newFragmentTop, "newFragmentTop")
                .addToBackStack(null)
                .commitAllowingStateLoss();

我也尝试获取 getApplicationContext() 但我无法从中获取 getSupportFragmentManager() 。如何在不启动活动的情况下打开片段?

标签: android-fragmentsandroid-activityandroid-context

解决方案


推荐阅读